seesharper / LightInject.Microsoft.DependencyInjection

Implements Microsoft.Extensions.DependencyInjection.Abstraction
MIT License
47 stars 13 forks source link

LightInject.Microsoft.DependencyInjection

AppVeyor [NuGet]() [GitHub tag]()

Implements the Microsoft.Extensions.DependencyInjection.Abstractions and makes it possible to create an IServiceProvider that is 100% compatible with the Microsoft.Extensions.DependencyInjection.Specification.Tests.

Note: This package is NOT meant to be used directly with AspNetCore applications. If the target application is an AspNetCore application, use the LightInject.Microsoft.Hosting package instead.

Installing

dotnet add package LightInject.Microsoft.DependencyInjection

Usage

var services = new ServiceCollection();
services.AddTransient<Foo>();
var provider = services.CreateLightInjectServiceProvider();

It is also possible to create an IServiceProvider directly from an IServiceContainer instance.

var container = new ServiceContainer(Options.Default.WithMicrosoftSettings);
var provider = container.CreateServiceProvider();

Note: Make sure that the Options.Default.WithMicrosoftSettings is passed in as options when creating the container. This makes the provider compliant with the default provider from Microsoft.