SaaS CMS has officially launched! Learn more now.

Class ClassFactory

Class factory for the basic classes for object storage and retrieval.

Inheritance
System.Object
ClassFactory
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.BaseLibrary
Assembly: EPiServer.BaseLibrary.dll
Version: 7.19.2
Syntax
public sealed class ClassFactory
Remarks

Note that ClassFactory must be initialized by assigning the Instance property an instantiated object that implements the IClassFactory interface. This will usually be performed by config-file based configuration, but can be made manually.

Properties

Instance

The actual class factory instance.

Declaration
public static IBaseLibraryFactory Instance { get; set; }
Property Value
Type Description
IBaseLibraryFactory
Remarks

Accessing the Instance getter without first setting it will cause a ClassFactoryException. To check if the class factory has been initialized you can look at the IsInitialized property.

IsInitialized

Check if class factory has been initialized.

Declaration
public static bool IsInitialized { get; }
Property Value
Type Description
System.Boolean

Methods

ClearRegistrations()

Remove all class registrations.

Declaration
public static void ClearRegistrations()

CreateContext()

Create a context object.

Declaration
public static IContext CreateContext()
Returns
Type Description
IContext

An object instance that implements IContext.

CreateInstance(Type, Object[])

Create the object implementation for the requested type.

Declaration
public static object CreateInstance(Type baseType, params object[] constructorParameters)
Parameters
Type Name Description
System.Type baseType

The interface or base class that we request an object instance for.

System.Object[] constructorParameters

Optional parameters to pass to a constructor.

Returns
Type Description
System.Object

The created object instance.

Remarks

This method should be considered a "last resort" when creating objects from application-level code. Object creation should be wrapped by more specific class factory objects that can handle constructor- based object creation.

CreateItem(Object, String)

Declaration
public static IItem CreateItem(object id, string name)
Parameters
Type Name Description
System.Object id
System.String name
Returns
Type Description
IItem

CreateItemList<IDTYPE, ITEMTYPE>(Object)

Declaration
public static IItemList<IDTYPE, ITEMTYPE> CreateItemList<IDTYPE, ITEMTYPE>(object containerId)

    where ITEMTYPE : IItem
Parameters
Type Name Description
System.Object containerId
Returns
Type Description
IItemList<IDTYPE, ITEMTYPE>
Type Parameters
Name Description
IDTYPE
ITEMTYPE

CreateItemList<IDTYPE, ITEMTYPE>(Object, Boolean)

Declaration
public static IItemList<IDTYPE, ITEMTYPE> CreateItemList<IDTYPE, ITEMTYPE>(object containerId, bool includeSubclasses)

    where ITEMTYPE : IItem
Parameters
Type Name Description
System.Object containerId
System.Boolean includeSubclasses
Returns
Type Description
IItemList<IDTYPE, ITEMTYPE>
Type Parameters
Name Description
IDTYPE
ITEMTYPE

CreateItemList<IDTYPE, ITEMTYPE>(String)

Declaration
public static IItemList<IDTYPE, ITEMTYPE> CreateItemList<IDTYPE, ITEMTYPE>(string containerPath)

    where ITEMTYPE : IItem
Parameters
Type Name Description
System.String containerPath
Returns
Type Description
IItemList<IDTYPE, ITEMTYPE>
Type Parameters
Name Description
IDTYPE
ITEMTYPE

CreateItemList<IDTYPE, ITEMTYPE>(String, Boolean)

Declaration
public static IItemList<IDTYPE, ITEMTYPE> CreateItemList<IDTYPE, ITEMTYPE>(string containerPath, bool includeSubclasses)

    where ITEMTYPE : IItem
Parameters
Type Name Description
System.String containerPath
System.Boolean includeSubclasses
Returns
Type Description
IItemList<IDTYPE, ITEMTYPE>
Type Parameters
Name Description
IDTYPE
ITEMTYPE

CreateRepository()

Create a repository object.

Declaration
public static IRepository CreateRepository()
Returns
Type Description
IRepository

An object instance that implements IRepository.

CreateSchema(String)

Declaration
public static ISchema CreateSchema(string schemaId)
Parameters
Type Name Description
System.String schemaId
Returns
Type Description
ISchema

CreateSession()

Create a session object.

Declaration
public static ISession CreateSession()
Returns
Type Description
ISession

An object that implements ISession.

CreateSession(IObjectStore)

Create a session object.

Declaration
public static ISession CreateSession(IObjectStore objectStore)
Parameters
Type Name Description
IObjectStore objectStore

The object store to create a session for.

Returns
Type Description
ISession

An object that implements ISession.

IsRegistered(Type)

Check if a type has been registered.

Declaration
public static bool IsRegistered(Type baseType)
Parameters
Type Name Description
System.Type baseType

The interface or base class.

Returns
Type Description
System.Boolean
Remarks

Will only register the mapping if no previous registration for baseType exists.

RegisterClass(Type, Type)

Register an implementation class for an interface/base class.

Declaration
public static void RegisterClass(Type baseType, Type mappedType)
Parameters
Type Name Description
System.Type baseType

The interface or base class.

System.Type mappedType

The class that implements the baseType interface or inherits from baseType.

Remarks

Note that mappedType must implement the interface identified by baseType or inherit from baseType. mappedType must also be a concrete class with a default constructor.

If baseType has already been registered, the old registration will be overwritten with the new parameters.