Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Interface IContentDataActivator

Describes the methods needed to resolve a IContentData type from a type parameter.

Namespace: EPiServer.DataAbstraction.RuntimeModel
Assembly: EPiServer.dll
Version: 11.20.7
Syntax
public interface IContentDataActivator
Remarks

This interface is used by ContentDataInterceptorHandler.

Examples
  The following code example demonstrates how to implement IModelTypeResolver. 
/// <summary>
/// The LoggableModelTypeResolver class try to log before creation of instance of model type.
/// This is a a dummy sample that shows how you can have affect on the creation of the requested type.
/// </summary>
public class LoggableModelTypeResolver : IContentDataActivator
{
private static ILogger _log = LogManager.GetLogger(typeof(LoggableModelTypeResolver));

/// <summary>
/// Resolves a <see cref="ContentData"/> instance from the specified type T passed to this instance.
/// </summary>
/// <typeparam name="T">Type of <see cref="ContentData"/> that should be resolved.</typeparam>
/// <returns>A new instance of type <typeparamref name="T"/>.</returns>
public T Create<T>() where T : class, IContentData
{
return Create(typeof(T)) as T;
}

/// <summary>
/// Resolves a <see cref="IContentData"/> instance from the specified model type.
/// </summary>
/// <param name="modelType">Type of <see cref="IContentData"/> that should be resolved.</param>
/// <returns>A new instance of the specified type.</returns>
public IContentData Create(Type modelType)
{
_log.Debug(String.Format("Model Type of {0} type is requested", modelType.FullName));
// Here is possibility to create a proxy for the model type.
return CreateProxy(modelType);

}

/// <summary>
/// Creates a IContent instance by creating a proxy of passed in type (must inherit <see cref="IContentData"/>)
/// and a MixIn class that implements <see cref="IContent"/>.
/// </summary>
/// <param name="modelType">Type of the model.</param>
/// <returns></returns>
public IContent CreateIContentMixin(Type modelType)
{
_log.Debug(String.Format("Mixin for Model Type of {0} type is requested", modelType.FullName));
throw new NotImplementedException();
}

/// <summary>
/// Creates proxy for the requested type t. In this sample we create an instance for the requested type t
/// </summary>
/// <param name="t">The t.</param>
/// <returns></returns>
private IContentData CreateProxy(Type t)
{
return Activator.CreateInstance(t) as IContentData;
}
}

Methods

Create(Type)

Resolves a IContentData instance from the specified model type.

Declaration
IContentData Create(Type modelType)
Parameters
Type Name Description
System.Type modelType

Type of IContentData that should be resolved.

Returns
Type Description
IContentData

A new instance of the specified type.

Create<T>()

Resolves a ContentData instance from the specified type T passed to this instance.

Declaration
T Create<T>()
    where T : class, IContentData
Returns
Type Description
T

A new instance of type T.

Type Parameters
Name Description
T

Type of IContentData that should be resolved.

Extension Methods