Skip to content

How to use Simple Injector in ASP.NET vNext #41

Closed
@mrchief

Description

@mrchief

I'm trying to hook up Simple Injector in a ASP.NET vNext project. Since, Simple Injector already implements IServiceProvider, I tried registering it like this:

public static class SimpleInjectorInitializer
{
  public static IServiceProvider Initialize(IConfiguration config, IServiceCollection services) {
    var container = new Container();
    container.RegisterCollection(services);

    // register app services

    container.Verify();

    return container;
  }
}

Startup.cs

public IServiceProvider ConfigureServices(IServiceCollection services) {
    // Add Application settings to the services container.
    services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));

    services.AddMvc();

    return SimpleInjectorInitializer.Initialize(Configuration, services);            
}

However, running the app gives me this error:

No service for type 'Microsoft.AspNet.Hosting.Builder.IApplicationBuilderFactory' has been registered.

Not using Simple Injector causes the app to run just fine (although it fails to inject anything but at least it doesn't throw this error).

Not sure what I'm missing.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions