Is the default IServiceProvider in ASP.NET Core thread safe?

Viewed 1692

I'm building a small ASP.NET Core app that also has a bunch of separate business logic that runs in its own thread. I was already using a IServiceProvider in the side program, so when I found out that ASP.NET Core also uses its own IServiceProvider, so I thought I could re-use only a single instance.

Now the question is, is the IServiceProvider that the web host uses thread safe? My setup basically looks like this

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();
1 Answers
Related