Dnn.Platform
Dnn.Platform copied to clipboard
Add Dependency Injection support in SkinObject
Description of problem
In DNN skin control code developer need clean and simple way to get services registered with DNN9 DI.
Description of solution
In DNN WebForms module we use ServiceProvider from PortalModuleBase.DependencyProvider. Expected solution will be expanding SkinObjectBase with same DependencyProvider property.
Description of alternatives considered
Something simmilar to this ugly, hacky workaround :-(
IServiceProvider ServiceProvider => ((IServiceScope)HttpContextSource.Current.Items[typeof(IServiceScope)]).ServiceProvider;
Additional context
Developing code that use dependencies registered in DNN9 DI, but without DNN9 DI is not nice. Expanding SkinObjectBase API with DependencyProvider looks as best solution/workaround in this moment, until constructor injection become reality.
Affected browser
- [x] Chrome
- [x] Firefox
- [x] Safari
- [x] Internet Explorer
- [x] Edge
Thx @bdukes for showing me dnn DI extension methods that can simplify code above.
IServiceScope currentScope = HttpContext.Current.GetScope();
IServiceProvider serviceProvider = HttpContext.Current.GetScope().ServiceProvider;
In https://github.com/dnnsoftware/Dnn.Platform/issues/4955#issuecomment-1033428800 is example code that can be used in Skin Object also. It is from 2sxc documentation - Depedency Injection in Dnn Skins and Modules. Thx @iJungleboy 👍
We have detected this issue has not had any activity during the last 90 days. That could mean this issue is no longer relevant and/or nobody has found the necessary time to address the issue. We are trying to keep the list of open issues limited to those issues that are relevant to the majority and to close the ones that have become 'stale' (inactive). If no further activity is detected within the next 14 days, the issue will be closed automatically. If new comments are are posted and/or a solution (pull request) is submitted for review that references this issue, the issue will not be closed. Closed issues can be reopened at any time in the future. Please remember those participating in this open source project are volunteers trying to help others and creating a better DNN Platform for all. Thank you for your continued involvement and contributions!
This issue has been closed automatically due to inactivity (as mentioned 14 days ago). Feel free to re-open the issue if you believe it is still relevant.