简体   繁体   中英

How to register an instance to the ServiceCollection in ASP.NET Core 1.0 RC2

I'm migrating my web app from ASP.NET Core RC1 to RC2. In RC2 the IServiceCollection doesn't have the AddInstance method anymore. How do I get the Configuration registered?

Here how it was done in RC1

public class Startup
{
    public IConfiguration Configuration { get; set; }

    public void ConfigureServices(IServiceCollection services)
    {
        // AddInstance doesn't exist
        services.AddInstance<IConfiguration>(Configuration);        
        .
        .       
    }
}

try this:

services.AddSingleton<IConfiguration>(Configuration);

I had same problem like you and I solved it with this.

Tomas B.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM