beetlex-io / FastHttpApi

a lightweight and high-performance http/websocket service component in the dotnet core platform that supports TLS.
Apache License 2.0
650 stars 175 forks source link

关于注入问题的疑问 #172

Closed nodyang closed 2 years ago

nodyang commented 2 years ago

image image

services.AddSingleton<IBackgroundRunService, BackgroundRunService>(); 理论上我的 BackgroundService 和 FastHttpApi controller 对IBackgroundRunService 的持有 应该是同一个对象 但测试效果好像不是 微软的 mvc api 是可以的 求解
image image

beetlex-io commented 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();
        }
nodyang commented 2 years ago

image image

我测试了一下。连正常的BackgroundService 都起不来。我先用mvc api 顶一下