
Enhancing Code Flexibility with Dependency Injection in DNN
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.
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
DNN Dependency Injection A Step to Modernization
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.
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
But That Works Right? Yes, it does, until changes happen What happens if you change MessageService to be CloudMessageService or TextMessageService? You edit EVERYWHERE
Traditional .NET Core DI Registration (Startup.cs)
Support for Dependency Injection All major module development paradiggms WebForms MVC Spa Similar to .NET Core Implementation but configured for DNN
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
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
Module Implementation Examples Special thanks to Andrew Hoefling for the samples https://github.com/ahoefling/DNN.DependencyInjection.Samples
NuGet Package Install-Package DotNetNuke.DependencyInjection
Samples & Detail https://www.andrewhoefling.com/Blog/Post/dnn-dependency- injection Thanks Andrew!