EPiServer 中的 IContentRepository 与 IContentLoader

IContentRepository vs IContentLoader in EPiServer

在 EPiServer 7 中,我遇到了 2 个不同的接口来获取 EPiServer 存储库 - IContentRepository 和 IContentLoader。

示例:

 var repo = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();

和:

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

有人可以向我解释一下何时在另一个之前使用一个吗? 提前致谢。

何时在另一个之前使用一个取决于您要执行的操作

首先,让我们看一下它们的定义(在 world.episerver.com 中陈述)

IContentRepository

"IContentRepository 是主要的 API 定义了 IContent 对象的存储库方法 [...] 通过存储库,您可以执行 CRUD(创建、读取、更新、删除)操作以及对内容实例的其他操作,例如列出和移动(即实现 EPiServer.Core.IContent 的实例)。"

IContentLoader

"描述可用于从存储库读取内容数据对象的服务。"

如定义所述,IContentLoader 用于读取内容,例如它不支持所有的 CRUD 性能。 轶事:IContentRepository 实现接口 IContentLoader。

更简短的答案:

如果您计划在存储库中 修改 content/data,请使用 IContentRepository

如果您只计划在存储库中 阅读 content/data,请使用 IContentLoader

希望这能为您澄清!