Posts

Showing posts with the label Dependency Injection

Calling 'BuildServiceProvider' From Application Code Results In Copy Of Singleton Warning. How Do I Avoid This?

Image
Answer : If called BuildServiceProvider() in ConfigureServices, shown warning "Calling 'BuildServiceProvider' from application code results in a additional copy of Singleton services being created" I solved this issue: Create another function (which passed argument is IServiceCollection) and into the function call BuildServiceProvider() For example your code it should be: public void ConfigureServices(IServiceCollection services) { if (HostingEnvironment.EnvironmentName == "Local") { services.AddHealthChecksUI() .AddHealthChecks() .AddCheck<TestWebApiControllerHealthCheck>("HomePageHealthCheck") .AddCheck<DatabaseHealthCheck>("DatabaseHealthCheck"); } services.Configure<PwdrsSettings>(Configuration.GetSection("MySettings")); services.AddDbContext<PwdrsContext>(o => o.UseSqlServer(Configuration.GetConnectionString("PwdrsConnectionRoot...