Dependency Injection is still fairly new to Dnn. As of now you can register interfaces/objects using the DnnStartup interface. But you cannot initialize code using the Service Provider. There is no startup-method to register to, which is called once all services are registered.
This causes some major limitations and problems:
You cannot do a clean startup of your code which would require registered services
If you work around this by keeping track of the IServiceCollection which was given at StartUp you can use this at a later time, but any singleton you register will get lost again, because it's not made using the root ServiceProvider Dnn uses on DotNetNuke.Common.Globals.DependencyProvider
As of now the only workaround is to access the DotNetNuke.Common.Globals.DependencyProvider using reflection (because it's internal), which is really bad.
Description of solution
There should be a clear interface to register startup code just like .net core does it. So there should be the register call (ATM IDnnStartup.ConfigureServices(...) but there should also be something similar like IDnnConfigure.Configure(...) which passes in objects incl. the global ServiceProvider to setup / configure anything else.
Description of problem
Dependency Injection is still fairly new to Dnn. As of now you can register interfaces/objects using the
DnnStartup
interface. But you cannot initialize code using the Service Provider. There is no startup-method to register to, which is called once all services are registered.This causes some major limitations and problems:
IServiceCollection
which was given at StartUp you can use this at a later time, but any singleton you register will get lost again, because it's not made using the root ServiceProvider Dnn uses onDotNetNuke.Common.Globals.DependencyProvider
As of now the only workaround is to access the
DotNetNuke.Common.Globals.DependencyProvider
using reflection (because it's internal), which is really bad.Description of solution
There should be a clear interface to register startup code just like .net core does it. So there should be the register call (ATM
IDnnStartup.ConfigureServices(...)
but there should also be something similar likeIDnnConfigure.Configure(...)
which passes in objects incl. the global ServiceProvider to setup / configure anything else.Affected browser: all
Keywords: DependencyInjection