Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Adding to IServiceCollection in Configure()

$
0
0

After adding most of my services in ConfigureServices(), One of the services is instantiated using app.ApplicationServices.GetServices<> at the beginning of Configure(). This utilizes the ServiceProvider instance. This occurs at the beginning of the method, and the service adds some more services to ServiceCollection which was preserved in the original ConfigureServices() call. The problem is that these new services are not available via the ServiceProvider instance. Creating another ServiceProvider instance from the ServiceCollection would lose previously modified and needed singletons.

Is there a way to accomplish this the way the DI container works as is? Should I switch to a different DI container? If so, which one? Thank  you.

As an aside, I downloaded the DependencyInjection, Metadata, and Hosting github repos. The code around the ServiceProviderEngine is deep and hard to understand. Ultimately, a reference to the ServiceCollection is preserved in the internal property and class CallSiteFactory inside the internal base class ServiceProviderEngine. The private method Populate() initializes the _descriptorLookup data member. It would be nice for ServiceProvider to have a Refresh() method that would call down into the CallSiteFactory and blow away and call Populate() to recreate the _descriptorLookup data member.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>