Table of Contents

Class ObjectFactory<T>

Namespace
CMS.Core
Assembly
CMS.Core.dll

Class that provides construction of the objects of given class

public class ObjectFactory<T> : IObjectFactory

Type Parameters

T
Inheritance
object
ObjectFactory<T>
Implements
Derived
Extension Methods

Constructors

ObjectFactory()

public ObjectFactory()

Properties

Constructor

Constructor used for dependency injection

protected ConstructorInfo Constructor { get; set; }

Property Value

ConstructorInfo

CreatedType

Returns the type created by this factory

public Type CreatedType { get; protected set; }

Property Value

Type

CurrentFactory

Current factory to create objects.

public static IObjectFactory CurrentFactory { get; }

Property Value

IObjectFactory

Initializer

Object initialization function

public Func<T, object> Initializer { get; set; }

Property Value

Func<T, object>

Singleton

Singleton instance of the created object type

public object Singleton { get; }

Property Value

object

Methods

CanCreateObject(object)

Returns true if the factory is able to create the object based on the given parameter

public virtual bool CanCreateObject(object parameter)

Parameters

parameter object

Object parameter

Returns

bool

CreateInstance()

Creates a new instance of the object

protected object CreateInstance()

Returns

object

CreateNewObject()

Creates and returns a new object

public virtual object CreateNewObject()

Returns

object

New()

Creates a new object of the given type

public static T New()

Returns

T

SetObjectTypeTo(Type, bool, bool)

Sets the object type created by the factory to the given type.

public static void SetObjectTypeTo(Type newType, bool canBeReplaced = false, bool replaceExisting = true)

Parameters

newType Type

Type to be crated by the factory.

canBeReplaced bool

If true, the given object type can be replaced by other object type

replaceExisting bool

If true, the service replaces existing if service is already initialized

SetObjectTypeTo<NewType>(bool, bool)

Sets the object type created by the factory to the given type.

public static void SetObjectTypeTo<NewType>(bool canBeReplaced = false, bool replaceExisting = true) where NewType : T

Parameters

canBeReplaced bool

If true, the given object type can be replaced by other object type

replaceExisting bool

If true, the service replaces existing if service is already initialized

Type Parameters

NewType

StaticSingleton()

Provides a static singleton instance of the object implementing this interface

public static T StaticSingleton()

Returns

T