November Happy Hour will be moved to Thursday December 5th.

Class EntityProviderHandler

Resolve and register IEntityProvider implementations for .NET types

Inheritance
System.Object
EntityProviderHandler
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.Data.Entity
Assembly: EPiServer.Data.dll
Version: 10.10.4
Syntax
public class EntityProviderHandler
Examples

Register an entity provider as follows:

    [ModuleDependency(typeof(DataInitialization))]
public class EntityProviderRegistration : IInitializableModule
{
public void Initialize(Framework.Initialization.InitializationEngine context)
{
    EntityProviderHandler.Instance.RegisterEntityProvider<MyEntityProvider, MyEntity>();
}

public void Uninitialize(Framework.Initialization.InitializationEngine context) {
}

public void Preload(string[] parameters) { } }

Resolve an entity provider as follows:

        public void ResolveAnEntityProvider1()
{
    IEntityProvider provider = EntityProviderHandler.Instance.GetEntityProvider<MyEntity>();
}

Register an entity provider as follows when the type is not known at compile-time:

        public void ResolveAnEntityProvider1(Type type)
{
    IEntityProvider provider = EntityProviderHandler.Instance.GetEntityProvider(type);
}

Constructors

EntityProviderHandler()

Initializes a new instance of this class.

Declaration
public EntityProviderHandler()

Properties

Instance

The globally available instance of the entity repository.

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

This instance is being initialized by DataInitialization and will be null otherwise

Methods

GetEntityProvider(Type)

Gets the IEntityProvider that handles instantiation of the specified type

Declaration
public virtual IEntityProvider GetEntityProvider(Type entityType)
Parameters
Type Name Description
System.Type entityType

The System.Type that is required to be supported by the returned IEntityProvider

Returns
Type Description
IEntityProvider

Returns an instance of the IEntityProvider configured for the type requested in the entityType parameter, or null if no provider is found.

GetEntityProvider<TEntity>()

Gets the IEntityProvider that handles instantiation of the specified type

Declaration
public virtual IEntityProvider GetEntityProvider<TEntity>()
    where TEntity : IEntity
Returns
Type Description
IEntityProvider

Returns an instance of the IEntityProvider configured for the type requested in the TEntity parameter, or null if no provider is found.

Type Parameters
Name Description
TEntity

The type of the entity which you are requesting the provider for

RegisterEntityProvider(IEntityProvider, Type[])

Registers a IEntityProvider that handles instantiation of the specified type

Declaration
public virtual void RegisterEntityProvider(IEntityProvider entityProvider, params Type[] supportedTypes)
Parameters
Type Name Description
IEntityProvider entityProvider

The instance of the IEntityProvider configured for the types requested

System.Type[] supportedTypes

A list of System.Type that is supported by the IEntityProvider

RegisterEntityProvider<TEntityProvider, TSupportedType>()

Registers a IEntityProvider that handles instantiation of the specified type

Declaration
public virtual void RegisterEntityProvider<TEntityProvider, TSupportedType>()
    where TEntityProvider : IEntityProvider, new()
    where TSupportedType : IEntity
Type Parameters
Name Description
TEntityProvider

The instance of the IEntityProvider configured for the type requested

TSupportedType

The System.Type that is required to be supported by the IEntityProvider

Remarks

If an instance of TEntityProvider is already added as a provider the TSupportedType will point to the same instance.

Extension Methods