Alternate to EPDataFactory

Vote:
 

Hi,

I am using the below in episerver 6 R2 , to get page data 

PageData page = Global.EPDataFactory.GetPage(new PageReference(ErrorPageID));

What class i can use in Episerver 7 , as EPDataFactory is no more available

R

D

#208053
Oct 11, 2019 13:45
Vote:
 

var contentrepo = ServiceLocator.Current.GetInstance<IContentRepository>();
var content = contentrepo .Get<IContent>(contentReference);

using dependecy injection for getting IContentRepository preferred :)

#208054
Edited, Oct 11, 2019 13:57
Dinesh Yadav - Oct 11, 2019 14:34
Thanks Daniel , is the below a collection ?
var content = contentrepo .Get
Vote:
 

Nope. Not that one. It will return a single content item. If you want a list of items below the node you can use .GetChildren() instead. 

If you already know you have a page (not an image or block etc) you can instead use 

var page= contentrepo .Get<PageData>(contentReference);

After that it's pretty similar to Episerver 6. You can check propeties etc.

#208063
Edited, Oct 11, 2019 15:34
Vote:
 

DataFactory can still be used in CMS 11.13.x (latest version). Based on the name EPDataFactory it sounds like it is a custom wrapper in your code, or a 3rd party library. 

But yes, using IContentRepository in a constructor injection way as Daniel suggested is the best way to move forward. 

#208094
Oct 14, 2019 7:49
Dinesh Yadav - Oct 14, 2019 11:14
Hi Quan,
Thanks for the info , You may be write , the code is written way back for Episerver 4 and 5 and then moved to 6

This thread is locked and should be used for reference only.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.