Implements Microsoft.Extensions.DependencyInjection.Abstraction
C#
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
build
src
.gitattributes Initial commit Jan 26, 2016
.gitignore
CHANGELOG.md
appveyor.yml
nuget.config
readme.md

readme.md

LightInject.Microsoft.DependencyInjection

AppVeyor NuGet GitHub tag

Enables LightInject to be used as the service container in ASP.NET Core and Entity Framework 7 applications.

Installing

"dependencies": {
  "LightInject.Microsoft.DependencyInjection": "<version>"
}

Usage

public class Startup
{       
    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        var container = new ServiceContainer();
        return container.CreateServiceProvider(services);
    }
    
    public void Configure(IApplicationBuilder app)
    {          
        app.Run(async (context) =>
        {
            await context.Response.WriteAsync("Hello from LightInject");
        });
    }
}

Controllers

By default, controllers are not actually created by LightInject. They are created by the ASP.NET infrastructure and uses LightInject to resolve its dependencies. To enable LightInject to create the controller instances, we need to add the following line.

services.AddMvc().AddControllersAsServices();

.Net Core 2.0

Requirements:

  • >= LightInject 5.1.0
  • >= LightInject.Microsoft.DependencyInjection 2.0.3

In addition we need to turn of propertyinjection

var containerOptions = new ContainerOptions { EnablePropertyInjection = false } 
var container = new ServiceContainer(containerOptions);