Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Episerver - Why BlockData doesn't implement IContent

Does anybody knows why BlockData class doesn't directly implement IContent? I know that during BlockData is being retrieve from database, proxy created by Castle implements IContent.

If StackOverflow isn't suitable place for this kind of a question, please move it.

like image 243
gringo_dave Avatar asked Apr 29 '15 12:04

gringo_dave


2 Answers

Johan Björnfot at EPiServer explains some of the details in this post.

Excerpt:

"In previous versions of CMS was pages (PageData) the only content type that the content repository (traditionally DataFactory) handled. In CMS7 this has changed so now content repository (IContentRepository) handles IContent instances. This means that the requirement for a .NET type to be possible to save/load from content repository is that it implements the interface EPiServer.Core.IContent.

There are some implementations of IContent built into CMS like PageData and ContentFolder (used to group shared block instances) and it is also possible to register custom IContent implementations.If you look at BlockData though you will notice that it doesn’t implement IContent, how is then shared block instances handled?

The answer is that during runtime when a shared block instance is created (e.g. through a call to IContentRepository.GetDefault where T is a type inheriting from BlockData) the CMS will create a new .NET type inheriting T using a technic called mixin where the new generated subclass will implement some extra interfaces (including IContent)."

like image 161
Ted Nyberg Avatar answered Nov 04 '22 21:11

Ted Nyberg


BlockData does implement IContent as it is intended to work both when added to another content item such as a PageData instance (a.k.a. Local Block), and as a standalone instance (a.k.a.Shared Block). In latter case the interface is added by using a mix-in though Castle Windsor so that it can be referenced.

The decision for this construct was based on wanting to be able to use the same rendering templates regardless if a block is local or shared. Therefor the choice stood between having a large number of empty properties on local blocks or the current solution using mixins. Both options were tested and mixins was selected as the preferred solution even though it's not a perfect one.

like image 4
Henrik N Avatar answered Nov 04 '22 19:11

Henrik N