DataFactory Class

Assembly: EPiServer (in EPiServer.dll) Version: 7.0.586.1

Syntax:

C#
[ServiceConfigurationAttribute(ServiceType = typeof(IContentSource), FactoryMember = "Instance", 
	Lifecycle = ServiceInstanceScope.Singleton)]
[ServiceConfigurationAttribute(ServiceType = typeof(IContentModelUsage), FactoryMember = "Instance", 
	Lifecycle = ServiceInstanceScope.Singleton)]
[ServiceConfigurationAttribute(ServiceType = typeof(IContentRepository), FactoryMember = "Instance", 
	Lifecycle = ServiceInstanceScope.Singleton)]
[ServiceConfigurationAttribute(ServiceType = typeof(IPageSource), FactoryMember = "Instance", 
	Lifecycle = ServiceInstanceScope.Singleton)]
[ServiceConfigurationAttribute(ServiceType = typeof(IPageCriteriaQueryService), FactoryMember = "Instance", 
	Lifecycle = ServiceInstanceScope.Singleton)]
[ServiceConfigurationAttribute(ServiceType = typeof(IContentSecurityRepository), FactoryMember = "Instance", 
	Lifecycle = ServiceInstanceScope.Singleton)]
[ServiceConfigurationAttribute(ServiceType = typeof(IContentLoader), FactoryMember = "Instance", 
	Lifecycle = ServiceInstanceScope.Singleton)]
[ServiceConfigurationAttribute(ServiceType = typeof(IPageStatistics), FactoryMember = "Instance", 
	Lifecycle = ServiceInstanceScope.Singleton)]
[ServiceConfigurationAttribute(ServiceType = typeof(IContentEvents), FactoryMember = "Instance", 
	Lifecycle = ServiceInstanceScope.Singleton)]
[ServiceConfigurationAttribute(ServiceType = typeof(IContentVersionRepository), FactoryMember = "Instance", 
	Lifecycle = ServiceInstanceScope.Singleton)]
[ServiceConfigurationAttribute(ServiceType = typeof(IContentProviderManager), FactoryMember = "Instance", 
	Lifecycle = ServiceInstanceScope.Singleton)]
[ServiceConfigurationAttribute(ServiceType = typeof(IEnterpriseSettings), FactoryMember = "Instance", 
	Lifecycle = ServiceInstanceScope.Singleton)]
public class DataFactory : PageStoreBase, 
	IPageCriteriaQueryService, IPageSource, IContentSource, IPageStatistics, IContentVersionRepository, 
	IContentProviderManager, IEnterpriseSettings, IContentModelUsage, IContentRepository, IContentLoader, 
	IContentSecurityRepository

Master data source in EPiServer CMS. It's the default implemenation of the IContentRepository interface, as well as several other page related interfaces.

Methods

Name
Copy(ContentReference, ContentReference, AccessLevel, AccessLevel, Boolean)
Copy(IContentRepository, ContentReference, ContentReference)
Copy(PageReference, PageReference)
Copy(PageReference, PageReference, AccessLevel, AccessLevel, Boolean, Boolean)
Copy(PageReference, PageReference, Boolean)
Copy(PageReference, PageReference, Boolean, Boolean)
CreateLanguageBranch(PageReference, ILanguageSelector)
CreateLanguageBranch(PageReference, ILanguageSelector, AccessLevel)
CreateLanguageBranch<T>(ContentReference, ILanguageSelector, AccessLevel)
CreateLanguageBranch<T>(IContentRepository, ContentReference, ILanguageSelector)
CreateSaveEventArgs(IContent, SaveAction, AccessLevel)
Delete(ContentReference, Boolean, AccessLevel)
Delete(IContentRepository, ContentReference, Boolean)
Delete(PageReference, Boolean)
Delete(PageReference, Boolean, AccessLevel)
DeleteChildren(ContentReference, Boolean, AccessLevel)
DeleteChildren(PageReference, Boolean)
DeleteChildren(PageReference, Boolean, AccessLevel)
DeleteLanguageBranch(ContentReference, String, AccessLevel)
DeleteLanguageBranch(PageReference, String)
DeleteLanguageBranch(PageReference, String, AccessLevel)
DeleteVersion(ContentReference, AccessLevel)
DeleteVersion(PageReference)
Dispose
Dispose(Boolean)
FindAllPagesWithCriteria(PageReference, PropertyCriteriaCollection, String, ILanguageSelector)
FindPagesWithCriteria(PageReference, PropertyCriteriaCollection)
FindPagesWithCriteria(PageReference, PropertyCriteriaCollection, AccessLevel)
FindPagesWithCriteria(PageReference, PropertyCriteriaCollection, String)
FindPagesWithCriteria(PageReference, PropertyCriteriaCollection, String, ILanguageSelector)
FindPagesWithCriteria(PageReference, PropertyCriteriaCollection, String, ILanguageSelector, AccessLevel)
Get<T>(ContentReference)
Get<T>(ContentReference, ILanguageSelector)
Get<T>(Guid)
Get<T>(Guid, ILanguageSelector)
GetAncestors(ContentReference)
GetAncestors(PageReference)
GetChildren(PageReference)
GetChildren(PageReference, ILanguageSelector)
GetChildren(PageReference, ILanguageSelector, Int32, Int32)
GetChildren(PageReference, Int32, Int32)
GetChildren<T>(ContentReference)
GetChildren<T>(ContentReference, ILanguageSelector)
GetChildren<T>(ContentReference, ILanguageSelector, int, int)
GetDefault<T>(ContentReference)
GetDefault<T>(ContentReference, ILanguageSelector)
GetDefault<T>(ContentReference, int, ILanguageSelector)
GetDefault<T>(IContentRepository, ContentReference, int)
GetDefaultPageData(PageReference, Int32)
GetDefaultPageData(PageReference, Int32, AccessLevel)
GetDefaultPageData(PageReference, Int32, ILanguageSelector)
GetDefaultPageData(PageReference, Int32, ILanguageSelector, AccessLevel)
GetDefaultPageData(PageReference, String)
GetDefaultPageData(PageReference, String, AccessLevel)
GetDefaultPageData(PageReference, String, ILanguageSelector)
GetDefaultPageData(PageReference, String, ILanguageSelector, AccessLevel)
GetDefaultPageData<T>(PageReference)
GetDefaultPageData<T>(PageReference, ILanguageSelector)
GetDescendents(ContentReference)
GetDescendents(PageReference)
GetItems(IEnumerable<ContentReference>, ILanguageSelector)
GetLanguageBranches(PageReference)
GetLanguageBranches(PageReference, AccessLevel)
GetLanguageBranches<T>(ContentReference)
GetLinksToPages(PageReference)
GetPage(PageReference)
GetPage(PageReference, AccessLevel)
GetPage(PageReference, ILanguageSelector)
GetPage(PageReference, ILanguageSelector, AccessLevel)
GetPageProvider(PageReference)
GetPageProvider(String)
GetPages(IList<PageReference>, ILanguageSelector)
GetParents(PageReference)
GetProvider(ContentReference)
GetProvider(String)
GetReferencesToContent(ContentReference, Boolean)
GetSettingsFromContent(ContentReference)
GetSettingsFromContent(ContentReference, Boolean)
GetSettingsFromPage(ContentReference)
GetSettingsFromPage(ContentReference, Boolean)
HasEntryPointChild(ContentReference)
Initialize(EPiServerSection)
IsCapabilitySupported(ContentReference, PageProviderCapabilities)
IsWastebasket(ContentReference)
ListDelayedPublish
ListPublishedVersions(PageReference)
ListVersions(PageReference)
ListVersions(PageReference, String)
LoadPublishedVersion(PageReference)
LoadPublishedVersion(PageReference, String)
LoadVersion(PageReference)
Move(ContentReference, ContentReference, AccessLevel, AccessLevel)
Move(IContentRepository, ContentReference, ContentReference)
Move(PageReference, PageReference)
Move(PageReference, PageReference, AccessLevel, AccessLevel)
MoveToWastebasket(ContentReference, String)
MoveToWastebasket(IContentRepository, ContentReference)
MoveToWastebasket(PageReference)
OnContentSecurityDescriptorSaved(ContentReference, IContentSecurityDescriptor, SecuritySaveType)
Ping(String)
RaiseCancellableDeleteEvent(String, String, DeleteContentEventArgs)
RaiseCancellablePageEvent(String, String, ContentEventArgs)
RaiseChildrenEvent(String, ChildrenEventArgs)
RaiseDeleteEvent(String, DeleteContentEventArgs)
RaisePageEvent(String, ContentEventArgs)
RaisePageEvent(String, IList<PageReference>, ContentEventArgs)
ResetCounters
ResolveContentFolder(Int32)
ResolvePageFolder(Int32)
Save(IContent, SaveAction, AccessLevel)
Save(IContentRepository, IContent, SaveAction)
Save(PageData, SaveAction)
Save(PageData, SaveAction, AccessLevel)

Properties

Name
CurrentPage
Instance
ListingFetchCacheHits
ListingFetchCount
ListingFetchDatabaseReads
PageFetchCacheHits
PageFetchCount
PageFetchDatabaseReads
PermanentLinkMapper
ProviderMap

Events

Name
CheckedInPage(C#public event PageEventHandler CheckedInPage
CheckingInPage(C#public event PageEventHandler CheckingInPage
CreatedPage(C#public event PageEventHandler CreatedPage
CreatingPage(C#public event PageEventHandler CreatingPage
DeletedPage(C#public event PageEventHandler DeletedPage
DeletedPageLanguage(C#public event PageEventHandler DeletedPageLanguage
DeletingPage(C#public event PageEventHandler DeletingPage
DeletingPageLanguage(C#public event PageEventHandler DeletingPageLanguage
EventHandler<ContentEventArgs> CheckedInContent
EventHandler<ContentEventArgs> CheckingInContent
EventHandler<ContentEventArgs> CreatedContent
EventHandler<ContentEventArgs> CreatingContent
EventHandler<ContentEventArgs> DeletedContentLanguage
EventHandler<ContentEventArgs> DeletedContentVersion
EventHandler<ContentEventArgs> DeletingContentLanguage
EventHandler<ContentEventArgs> DeletingContentVersion
EventHandler<ContentEventArgs> FailedLoadingContent
EventHandler<ContentEventArgs> LoadedContent
EventHandler<ContentEventArgs> LoadedDefaultContent
EventHandler<ContentEventArgs> LoadingContent
EventHandler<ContentEventArgs> LoadingDefaultContent
EventHandler<ContentEventArgs> MovedContent
EventHandler<ContentEventArgs> MovingContent
EventHandler<ContentEventArgs> PublishedContent
EventHandler<ContentEventArgs> PublishingContent
EventHandler<ContentEventArgs> SavedContent
EventHandler<ContentEventArgs> SavingContent
EventHandler<DeleteContentEventArgs> DeletedContent
EventHandler<DeleteContentEventArgs> DeletingContent
FailedLoadingChildren(C#public event ChildrenEventHandler FailedLoadingChildren
FailedLoadingPage(C#public event PageEventHandler FailedLoadingPage
FinishedLoadingChildren(C#public event ChildrenEventHandler FinishedLoadingChildren
FinishedLoadingPage(C#public event PageEventHandler FinishedLoadingPage
LoadedChildren(C#public event ChildrenEventHandler LoadedChildren
LoadedDefaultPageData(C#public event PageEventHandler LoadedDefaultPageData
LoadedPage(C#public event PageEventHandler LoadedPage
LoadingChildren(C#public event ChildrenEventHandler LoadingChildren
LoadingDefaultPageData(C#public event PageEventHandler LoadingDefaultPageData
LoadingPage(C#public event PageEventHandler LoadingPage
MovedPage(C#public event PageEventHandler MovedPage
MovingPage(C#public event PageEventHandler MovingPage
PublishedPage(C#public event PageEventHandler PublishedPage
PublishingPage(C#public event PageEventHandler PublishingPage
SavedPage(C#public event PageEventHandler SavedPage
SavingPage(C#public event PageEventHandler SavingPage

Remarks

DataFactory is responsible for all page-related activities, including loading, saving, deleting, caching, moving, etc. The class also has events, which you can use to extend the functionality of EPiServer. For example, if you want to send an e-mail whenever a page is published, use one of the PublishingPage or PublishedPage events exposed by DataFactory. You can even cancel events, adding another level of authorization.

DataFactory has full support for redirecting a request to a remote EPiServer site, the ProviderName property on ContentReference specifies the short name for the remote site to operate against. This site must be configured in Admin mode prior to usage.

You can also monitor how the page cache performs by checking the different hit counters, like PageFetchDatabaseReads, ListingFetchDatabaseReads, PageFetchCacheHits etc.

Note
You can access the DataFactory either through the static property EPiServer.DataFactory.Instance, or you can have it injected from the IOC container. If you are using the dependancy injection way, make sure to always work with the interfaces.

Do not instantiate your own DataFactory classes if you are not certain that you have to. A DataFactory object not created by EPiServer will not use the cache, and the performance will be significantly lower.

Examples

This following code example shows how to use the global DataFactory instance to fetch a page with a given ID.

CopyC#
PageData page = EPiServer.DataFactory.Instance.GetPage(new PageReference(1234));
The following code example demonstrates the usage of DataFactory to delete a page.
CopyC#
EPiServer.DataFactory.Instance.Delete(new PageReference(1203), false);
The following example shows how to use the global DataFactory instance to fetch a page with a given ID on a remote server. You must configure the site in Admin mode under "Remote sites".
CopyC#
PageData page = EPiServer.DataFactory.Instance.GetPage(new PageReference(1234, "intranet"));
The following code sample demonstrates how you can create a new page of your specific PageData type.
CopyC#
public class TestClass
{
    public void CreateNewPage(PageReference parent)
    {
        IContentRepository factory = DataFactory.Instance;
        MyPageData newPage = factory.GetDefault<MyPageData>(parent);
        newPage.MainBody = "<div>Hello World!</div>";
        factory.Save(newPage, SaveAction.Publish);
    }
}

[ContentType]
public class MyPageData : PageData
{
    public virtual string MainBody { get; set; }
}
The following code example demonstrates how to use the built-in statistics properties.
CopyC#
EPiServer.Core.IPageStatistics statisticsService = DataFactory.Instance;

// Pages
int pagesFromCache = statisticsService.PageFetchCacheHits;
int pagesFromDB = statisticsService.PageFetchDatabaseReads;
int totalPages = statisticsService.PageFetchCount;

double Ratio = Math.Round((double)pagesFromCache / (double)totalPages * 100, 2);

// Listings
int listingsFromCache = statisticsService.ListingFetchCacheHits;
int listingsFromDB = statisticsService.ListingFetchDatabaseReads;
int totalListings = statisticsService.ListingFetchCount;

double listingsRatio = Math.Round((double)listingsFromCache / (double)totalListings * 100, 2);

Inheritance