I am trying to get access to an instance of a custom class during the ConfigureServices
method.
I have read that I can build an intermediate service provider to do this:
public void ConfigureServices(IServiceCollection services)
{
// .... Other Stuff ....
services.AddSingleton<Wso2Actions>();
var serviceProvider = services.BuildServiceProvider();
var wso2Actions = serviceProvider.GetService<Wso2Actions>();
// .... Other stuff ....
I have 3 questions regarding this technique:
- What are the drawbacks to making this "Intermediate Service Provider"?
- Will my
wso2Actions
object still be managed by the dependency injection framework? (As if it had been injected later on?) - Would I be better off just "newing" up the object myself?
var wso2Actions = new Wso2Actions(); services.AddSingleton<Wso2Actions>(wso2Actions);
- I seem to recall reading that passing an instance into the DI engine results in poorer lifetime management.