You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Its possible to create child containers purely using the native / built in microsoft ServiceProvider.
For anyone that is interested in this take a look at:
This is obviously accurate and sensible advice given no alternatives. However here I am just presenting an alternative. If the you generally happy with the native ServiceProvider and how it works, and just want "Child Container" feature, then it's no longer necessary to spend time evaluating and switching to a third party DI container implementation. You can "stick with the devil you know".
In my view, a child container is just another instance of a container, with very slightly amended logic about which service registrations are honoured. To reflect this, the library provides a means to configure child service collections (a specialized implementation of IServiceCollection that also allows the immutable parents servide descriptors to be evaluated), and then configure any third party container (that doesn't support "child container" feature inherently) as a child container - as long as it supports being built from IEnumerable<ServiceDescriptor>.
I'm putting this out there in case its useful, feedback welcome.
Feel free to close this discussion if you are cleaning up issues.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Its possible to create child containers purely using the native / built in microsoft
ServiceProvider
.For anyone that is interested in this take a look at:
https://github.com/dazinator/Dazinator.Extensions.DependencyInjection/blob/develop/src/DependencyInjection.ChildContainers/README.md
The nuget package: https://www.nuget.org/packages/Dazinator.Extensions.DependencyInjection.ChildContainers/
I thought it would be good to register this as a discussion here, in case anyone searches for "child container" functionality and only comes accross advice stating you should swap out the native container to one that supports child containers
This is obviously accurate and sensible advice given no alternatives. However here I am just presenting an alternative. If the you generally happy with the native ServiceProvider and how it works, and just want "Child Container" feature, then it's no longer necessary to spend time evaluating and switching to a third party DI container implementation. You can "stick with the devil you know".
In my view, a child container is just another instance of a container, with very slightly amended logic about which service registrations are honoured. To reflect this, the library provides a means to configure child service collections (a specialized implementation of IServiceCollection that also allows the immutable parents servide descriptors to be evaluated), and then configure any third party container (that doesn't support "child container" feature inherently) as a child container - as long as it supports being built from
IEnumerable<ServiceDescriptor>
.I'm putting this out there in case its useful, feedback welcome.
Feel free to close this discussion if you are cleaning up issues.
Beta Was this translation helpful? Give feedback.
All reactions