Skip to main content

Posts

Showing posts with the label Dependency Injection

Implementing .Net core based Dependency Injection in Sitecore

Since version 8, Sitecore has started focusing on cleaner and extensible architecture with more and more plug and play features. One key improvement in version 8 was introducing dependency injection within Sitecore based on  .net core libraries for DI. So if you are creating an application in Sitecore and planning to use DI, you can always make use of inbuilt DI used by Sitecore. Obvious advantage is you wont be introducing any new paths in the solution and no new libraries will be introduced keeping the solution lightweight.  So, the obvious question - how do we do it? I am assuming here that you have basic understanding of a Sitecore application and dependency injection fundamentals. Hence, I will focus on steps needed to enable DI in Sitecore. Include the following DLLs to references in your project (in Foundation layer if you are following Helix principles) - Microsoft.Extensitons.DependencyInjection,  Microsoft.Extensions.DependencyInjection.Abstraction Create the configurator cla