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

Scopes in Microsoft.Extensions.DependencyInjection

$
0
0

I'm playing around with the new Microsoft DI and am trying to implement this in my project. I'm looking for examples on is how to implement a chain of 2 nested scopes from a the (shared) root ServiceCollection, like so: Root -> Level 1 -> Level 2. This would mean that the Root level resolves services as usual, level 1 resolves from level 1 and root, and level 2 resolves from level 2, level 1 and root, respectively.

IServiceScopeFactory.CreateScope gives me access to a scoped ServiceProvider, but what do I do when I want to register a service exclusively for that scope? I only have access to the root ServiceCollection, but not one for my scopes, only the provider.

Does the Microsoft DI support this kind of scoping? All suggestions are welcome.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



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