IContentRepository vs IContentLoader in EPiServer
Asked Answered
W

1

9

In EPiServer 7, I have come across 2 different interfaces to get a hold of the EPiServer repository - IContentRepository and IContentLoader.

Example:

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

and:

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

Could somebody explain to me when to use one in front of the other? Thanks in advance.

Wolverine answered 9/10, 2015 at 12:33 Comment(0)
P
16

When to use one in front of the other depends on the action you want to perform.

First of all, lets go through their definitions (stated on world.episerver.com)

IContentRepository

"IContentRepository is the primary API that defines repository methods for IContent objects [...] Through the repository, you can perform CRUD (Create, Read, Update, Delete) operations and other operations on content instances such as listing and move (that is, instances implementing EPiServer.Core.IContent)."

IContentLoader

"Describes a service that can be used to read content data objects from a repository."

As the definition states, IContentLoader is used for reading content, e.g. it does not support all of the CRUD performance. Anecdote: The IContentRepository implements the interface IContentLoader.

Shorter answer:

Use IContentRepository when you plan on modifying content/data in the repository.

Use IContentLoader when you only plan on reading content/data in the repository.

Hope this clarifies it for you!

Pazit answered 9/10, 2015 at 12:40 Comment(1)
Thx @ChrisRun. This surely clarifies it :)Wolverine

© 2022 - 2024 — McMap. All rights reserved.