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);
.
.
}
}
The ServiceCollection class keeps a list of the services, and returns a IServiceProvider object that can be used to access the registered services. Several extension methods can be used to register services: AddSingleton, AddTransient, and AddScoped.
IOptionsMonitor is a Singleton service that retrieves current option values at any time, which is especially useful in singleton dependencies. IOptionsSnapshot is a Scoped service and provides a snapshot of the options at the time the IOptionsSnapshot<T> object is constructed.
ASP.NET Core supports the dependency injection (DI) software design pattern, which is a technique for achieving Inversion of Control (IoC) between classes and their dependencies. For more information specific to dependency injection within MVC controllers, see Dependency injection into controllers in ASP.NET Core.
try this:
services.AddSingleton<IConfiguration>(Configuration);
I had same problem like you and I solved it with this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With