I have a service I wrote that helps with configuration. The service is set up in the Startup class's ConfigureServices method as:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddScoped<IMyService, MyService>();
...
}
I need to then get an instance of IMyService in the Startup class's Configure method. How do I do that?
Since you've already added your service with AddScoped
, all you need to do is add another parameter to the Configure
method with the correct type and the dependency injection system will take care of it for you:
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory,
IMyService myService)
{
//Snip
}
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