如何使用构造函数注入获取 IContentLoader 实例

How to get IContentLoader instance using constructor injection

我有这个代码

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

我想使用构造函数注入获取 IContentLoader 的实例。

如果您使用的是最新的 Episerver 版本(NuGet 包 EPiServer.ServiceLocation.StructureMap > 2.0),您应该能够简单地:

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