Dnn.Platform icon indicating copy to clipboard operation
Dnn.Platform copied to clipboard

Add Dependency Injection support in SkinObject

Open tvatavuk opened this issue 3 years ago • 3 comments

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

tvatavuk avatar Dec 08 '21 19:12 tvatavuk

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;

tvatavuk avatar Feb 02 '22 12:02 tvatavuk

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 👍

tvatavuk avatar Feb 09 '22 07:02 tvatavuk

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!

stale[bot] avatar Jul 31 '22 03:07 stale[bot]

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.

stale[bot] avatar Nov 02 '22 03:11 stale[bot]