Configure Hosting and Dependency Injection
masterFor advanced hosting scenarios, install BeetleX.FastHttpApi.Hosting. This allows you to use an HttpServer instance, configure TLS, and register services into the DI container using the .Setting method.
// Requires Install-Package BeetleX.FastHttpApi.Hosting
public class Program
{
static void Main(string[] args)
{
HttpServer host = new HttpServer(80);
host.UseTLS("test.pfx", "123456");
host.Setting((service, option) =>
{
service.AddTransient<UserInfo>();
option.LogToConsole = true;
option.LogLevel = BeetleX.EventArgs.LogType.Info;
});
host.RegisterComponent<Program>();
host.Run();
}
}
[Controller]
public class Home
{
public Home(UserInfo user) { mUser = user; }
public object Hello() { return mUser.Name; }
private UserInfo mUser;
}
public class UserInfo { public string Name { get; set; } = "admin"; }