Search code examples
episerver

How to get IContentLoader instance using constructor injection


I Have this code

var loader = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentLoader>();

I want to get the instance of IContentLoader using constructor injection.


Solution

  • If you're on a recent Episerver version (NuGet package EPiServer.ServiceLocation.StructureMap > 2.0), you should be able to simply:

    public MyPageController(IContentLoader contentLoader)
    {
       // Do something with contentLoader
    }