Closed nodyang closed 2 years ago
忘了当时的设计了,内部新建了ServiceCollection并复制了一下,改成这样启动fasthttpapi,在setting方法中注入试一下。
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();
}
我测试了一下。连正常的BackgroundService 都起不来。我先用mvc api 顶一下
services.AddSingleton<IBackgroundRunService, BackgroundRunService>(); 理论上我的 BackgroundService 和 FastHttpApi controller 对IBackgroundRunService 的持有 应该是同一个对象 但测试效果好像不是 微软的 mvc api 是可以的 求解