question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactor Globals.cs to use Dependency Injection

See original GitHub issue

Description 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:open
  • Created 4 years ago
  • Reactions:3
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
tpperlmancommented, Dec 3, 2019

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);

1reaction
valadascommented, Mar 23, 2023

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found