Class ObjectFactory<T>
Class that provides construction of the objects of given class
public class ObjectFactory<T> : IObjectFactory
Type Parameters
T
- Inheritance
-
objectObjectFactory<T>
- Implements
- Derived
- Extension Methods
Properties
CanReplaceCurrent
If true, the default object factory can be replaced by other factory
[Obsolete("Property was not intended for public use and will be removed.")]
[ObsoleteSince(29, 6)]
public static bool CanReplaceCurrent { get; }
Property Value
- bool
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
Initializer
Object initialization function
public Func<T, object> Initializer { get; set; }
Property Value
- Func<T, object>
IsInitialized
Returns true if the default factory is initialized
[Obsolete("Property was not intended for public use and will be removed.")]
[ObsoleteSince(29, 6)]
public static bool IsInitialized { get; }
Property Value
- bool
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
objectObject 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
CreateNewTypedObject()
Creates and returns a new object
[Obsolete("Method was not intended for public use and will be removed.")]
[ObsoleteSince(29, 6)]
public T CreateNewTypedObject()
Returns
- T
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
TypeType to be crated by the factory.
canBeReplaced
boolIf true, the given object type can be replaced by other object type
replaceExisting
boolIf 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
boolIf true, the given object type can be replaced by other object type
replaceExisting
boolIf 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
StaticSingleton<TParent>()
Returns static singleton for the given object type
[Obsolete("Method was not intended for public use and will be removed.")]
[ObsoleteSince(29, 6)]
public static T StaticSingleton<TParent>()
Returns
- T
Type Parameters
TParent