dnnsoftware / Dnn.Platform

DNN (formerly DotNetNuke) is the leading open source web content management platform (CMS) in the Microsoft ecosystem.
https://dnncommunity.org/
MIT License
1.03k stars 751 forks source link

Provide a clean Dependency Injection based Configure(...) method #5112

Open iJungleboy opened 2 years ago

iJungleboy commented 2 years ago

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:

  1. You cannot do a clean startup of your code which would require registered services
  2. 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.

Affected browser: all

Keywords: DependencyInjection

bdukes commented 2 years ago

Sounds good to me

valadas commented 1 year ago

Great idea