Enhancing Code Flexibility with Dependency Injection in DNN

dnn dependency injection a step to modernization n.w
1 / 18
Embed
Share

Discover the benefits of integrating dependency injection in DNN development, facilitating code flexibility, unit testing, and adherence to SOLID principles. Learn about the evolution from traditional practices to modern implementation in DNN versions. Explore how to leverage dependency injection for simplified code maintenance and scalability.

  • Dependency Injection
  • DNN
  • Code Flexibility
  • Unit Testing
  • SOLID

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. DNN Dependency Injection A Step to Modernization

  2. Why Dependency Injection Development is completed using interfaces allowing code to be swapped for implementations Code can be better unit tested for ongoing functionality Code can be validated BEFORE being executed Following SOLID principles results in code that is less complex and easier to understand.

  3. Introduction of Dependency Injection in DNN Current implementation was added in DNN 9.4.0 Enhancements came in 9.5.0 with a final change coming in 9.5.1 Older Service Locator pattern has existed for a while Current implementation follows .NET Core Standards

  4. What Code Used to Look Like

  5. Usage

  6. But That Works Right? Yes, it does, until changes happen What happens if you change MessageService to be CloudMessageService or TextMessageService? You edit EVERYWHERE

  7. Introduce Dependency Injection

  8. Traditional Dependency Injection Usage

  9. Traditional .NET Core DI Registration (Startup.cs)

  10. Support for Dependency Injection All major module development paradiggms WebForms MVC Spa Similar to .NET Core Implementation but configured for DNN

  11. Introducing IDnnStartup Base class allowing Dependency Injection to be Discovered Anything that would be done in .NET Core using Startup.cs would be done in this class Executed at startup

  12. Example

  13. Implementation Rules Aside from the IDnnStartup base class, all rules follow .NET Core Standards Constructor Injection for all except WebForms WebForms require a ServiceLocator process due to limitations in implementation ability

  14. Module Implementation Examples Special thanks to Andrew Hoefling for the samples https://github.com/ahoefling/DNN.DependencyInjection.Samples

  15. NuGet Package Install-Package DotNetNuke.DependencyInjection

  16. WebForms Service Locator

  17. MVC Just like everyone else

  18. Samples & Detail https://www.andrewhoefling.com/Blog/Post/dnn-dependency- injection Thanks Andrew!

More Related Content