-1

I Have this code

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

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

Janmejay Kumar
  • 309
  • 2
  • 7
  • Have you tried adding a constructor argument of type `IContentLoader`? Which version of Episerver are you running? Which version of the EPiServer.ServiceLocation.StructureMap package? – Ted Nyberg Oct 29 '18 at 08:04

1 Answers1

3

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
}
Ted Nyberg
  • 7,001
  • 7
  • 41
  • 72