Refactor Globals.cs to use Dependency Injection
See original GitHub issueDescription of problem
In DNN 9.4.0 we introduced Dependency Injection and it is time to start refactoring the Globals.cs
file to use Dependency Injection. This is a massive undertaking and should not be attempted in 1 Pull Request. This work item should serve as an epic that we can link others back to as we solve small problems.
Description of solution
Refactor sections of Globals.cs
into manageable interfaces grouped in logical chunks. For example all of the NavigateURL
methods should move to an interface called INavigationManager
.
Description of alternatives considered
N/A
Screenshots
N/A
Affected browser
- Chrome
- Firefox
- Safari
- Internet Explorer
- Edge
Work Items
A table of work items of chunks that we will break out the Globals.cs
into
Work Item ID | Manager | Description |
---|---|---|
#3159 | INavigationManager |
All navigation methods should exist in an easy to use interface |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:16 (11 by maintainers)
Top Results From Across the Web
Refactoring out Singletons/Globals to use Dependency ...
I'm working on a large codebase that has made extensive use of the Singleton pattern, as well as some Globals. I've just started...
Read more >How do I deal with global variables in existing legacy code ...
A better scheme would be dependency injection with no globals (or statics) whatsoever. Old code: int DEFAULT_QUUX = 5; int main() { Blip...
Read more >How to use Dependency Injection in Functional Programming
Dependency Injection is a technique to make the classes in Object Oriented Programming easier to test and configure.
Read more >MUST know Startup.cs To Program.cs REFACTORING tips ...
Program.cs is the file where we register things for dependency injection, rather than the file where we can get access-to-things auto-magically.
Read more >Refactoring with Dependency Inversion and Injection
In this post I want to show how to refactor with the Dependency Inversion Principle. I find it hard to create a mock...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @mitchelsellers!
So if I understand correctly the new way going forward would be to add a reference DotNetNuke.Abstractions in the project and replace entries like:
return DotNetNuke.Common.Globals.NavigateURL(SomeTabId);
with
using DotNetNuke.Abstractions;
...
protected INavigationManager NavigationManager { get; }
...
return NavigationManager.NavigateURL(SomeTabId);
In MVC you can get the services injected for you using constructor injection like described here: https://docs.dnncommunity.org/content/getting-started/development/fundamentals/dependency-injection/mvc/index.html
Note that since you need INavagationManager, this is already registered by DNN itself so for that one, you don’t need to also implement IDnnStartup