Skip to content

The library that transparently provides the missing child container feature of Microsoft's DependencyInjection library.

Notifications You must be signed in to change notification settings

bduman/ms-dependencyinjection-childcontainer

Repository files navigation

DependencyInjection.ChildContainer

Nuget Push Nuget

Coded as an add-on to existing microsoft dependency injection library. The creation of new concepts was avoided as much as possible.

Nuget

To use child container feature, install the NuGet package:

dotnet add package DependencyInjection.ChildContainer

Capabilities of Child Container -Child Service Provider-

  • Child container can use parent container's dependencies. (Both as service construct operations and direct access to parent's service provider.)
  • The parent container can indirectly access the services of the child container. (Just knowing the child container's name is enough.)
  • Child container is not allowed to override parent container's dependency. (A precaution to avoid misrepresentations and ambiguity.)
  • Child containers are built with lazy behavior. (If Microsoft had opened the service provider's build with an interface, maybe the opposite -eager- would have been possible.)

Usage

IServiceCollection parentCollection = new ServiceCollection();

// Create a child container
IServiceCollection childCollection = parentCollection.CreateChildCollection("child1");

// Build parent collection to get service provider
IServiceProvider parentServiceProvider = parentCollection.BuildServiceProvider();

// Access to child service provider from parent
IServiceProvider childServiceProvider = parentServiceProvider.GetChildServiceProvider("child1");

// Access to parent service provider from child
IServiceProvider parentServiceProvider = childServiceProvider.GetServices<IParentServiceProvider>();

About

The library that transparently provides the missing child container feature of Microsoft's DependencyInjection library.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages