2017-08-07 29 views
0

我正在構建一個小型的ASP.NET核心應用程序,它也有一堆獨立的業務邏輯,可以在自己的線程中運行。我在邊欄程序中已經使用了IServiceProvider,所以當我發現ASP.NET Core也使用它自己的IServiceProvider時,所以我認爲我可以重新使用一個實例。ASP.NET Core線程中的默認IServiceProvider是否安全?

現在的問題是,IServiceProvider Web主機使用線程安全嗎?我的設置基本如下

var host = new WebHostBuilder() 
      .UseKestrel() 
      .UseContentRoot(Directory.GetCurrentDirectory()) 
      .UseIISIntegration() 
      .UseStartup<Startup>() 
      .UseApplicationInsights() 
      .Build(); 

Task.Run(() => { 
    // here I access the IServiceProvider via `host.Services` 
    new Foo(host.Services).Run(); 
}); 

host.Run(); 

回答