2015-10-09 17 views
6

在EPiServer 7中,我遇到了兩個不同的接口來獲取EPiServer存儲庫 - IContentRepository和IContentLoader。EPiServer中的IContentRepository與IContentLoader

例子:

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

和:

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

有人能向我解釋什麼時候在前面的其他使用嗎? 在此先感謝。

回答

10

何時使用其中一個取決於您想要執行的動作

首先,讓我們通過他們的定義(上world.episerver.com說明)

IContentRepository

IContentRepository是主要的API,它定義了IContent對象存儲庫的方法[.. 。]通過存儲庫,您可以對列表和移動等內容實例(即實現EPiServer.Core.IContent的實例)執行CRUD(創建,讀取,更新,刪除)操作和其他操作。

IContentLoader

描述了可用於從儲存庫讀內容數據對象的一項服務。」

如定義所述,IContentLoader用於讀取內容,例如,它不支持所有的CRUD性能。軼事:IContentRepository實現接口IContentLoader。

較短的答案:

使用IContentRepository當你打算修改內容/數據倉庫。

使用IContentLoader當你只在閱讀內容/數據存儲庫中的計劃。

希望能爲你澄清它!

+0

Thx @ChrisRun。這肯定澄清它:) – ElC