/// <summary> /// Creates an instance of an object of type 'objType' using the default constructor /// </summary> /// <param name="objType">The type of the object to be created</param> /// <param name="resolver">Injection source</param> /// <returns>Created object</returns> public static object CreateObject(Type objType, IInjectionResolver resolver) { Contract.Requires(objType != null); Contract.Requires(resolver != null); return(ObjectInstantiationHelper.CreateObject(objType, resolver, null)); }
public void TestBuildInstanceCreatorFuncInDynAssembly() { ValidateFunc <TestSimpleClass>(ObjectInstantiationHelper.BuildCreatorFuncInDynAssembly(typeof(TestSimpleClass), null)); ValidateFunc <TestClassWithConstructor>(ObjectInstantiationHelper.BuildCreatorFuncInDynAssembly(typeof(TestClassWithConstructor), null)); var v3 = ValidateFunc <TestClassWithMarkedConstructor>(ObjectInstantiationHelper.BuildCreatorFuncInDynAssembly(typeof(TestClassWithMarkedConstructor), null)); Assert.AreEqual(10, v3.Val); }
public void TestBuildInstanceCreatorNoParamInDynAssembly() { ValidateInstCreator <TestSimpleClass>(ObjectInstantiationHelper.BuildInstanceCreatorNoParamInDynAssembly(typeof(TestSimpleClass), new TestInjectionResolver(), null)); ValidateInstCreator <TestClassWithConstructor>(ObjectInstantiationHelper.BuildInstanceCreatorNoParamInDynAssembly(typeof(TestClassWithConstructor), new TestInjectionResolver(), null)); var v3 = ValidateInstCreator <TestClassWithMarkedConstructor>(ObjectInstantiationHelper.BuildInstanceCreatorNoParamInDynAssembly(typeof(TestClassWithMarkedConstructor), new TestInjectionResolver(), null)); Assert.AreEqual(10, v3.Val); }
public void TestGetCompiledCreationFunction() { ValidateFunc <TestSimpleClass>(ObjectInstantiationHelper.GetCompiledCreationFunction(typeof(TestSimpleClass), null)); ValidateFunc <TestClassWithConstructor>(ObjectInstantiationHelper.GetCompiledCreationFunction(typeof(TestClassWithConstructor), null)); var v3 = ValidateFunc <TestClassWithMarkedConstructor>(ObjectInstantiationHelper.GetCompiledCreationFunction(typeof(TestClassWithMarkedConstructor), null)); Assert.AreEqual(10, v3.Val); }
/// <summary> /// Creates an instance of an object of type 'T' using the default constructor /// </summary> /// <typeparam name="T">The type of the object to be created</typeparam> /// <param name="resolver">Injection source</param> /// <returns>Created object</returns> public static T CreateObject <T>(IInjectionResolver resolver) { if (resolver == null) { throw new ArgumentNullException(nameof(resolver)); } return((T)ObjectInstantiationHelper.CreateObject(typeof(T), resolver, null)); }
/// <summary> /// Creates an instance of an object of 'objType' type using the parameterless constructor /// </summary> /// <param name="objType">The type of the object to be created</param> /// <returns>Created object</returns> public static object CreateObject(Type objType) { if (objType == null) { throw new ArgumentNullException(nameof(objType)); } return(ObjectInstantiationHelper.CreateObject(objType)); }
/// <summary> /// Creates an instance of an object of type 'objType' using the default constructor /// </summary> /// <param name="objType">The type of the object to be created</param> /// <param name="resolver">Injection source</param> /// <returns>Created object</returns> public static object CreateObject(Type objType, IInjectionResolver resolver) { if (objType == null) { throw new ArgumentNullException(nameof(objType)); } if (resolver == null) { throw new ArgumentNullException(nameof(resolver)); } return(ObjectInstantiationHelper.CreateObject(objType, resolver, null)); }
/// <summary> /// Creates a PerThreadLifetime container that resolves an instance of the specified object type /// </summary> /// <param name="objType">The type of the object that will be held by the lifetime container</param> /// <param name="injection">Injection resolver that will be used to create an instance if required</param> /// <param name="extInfo">Extended information supplied by the user (can be null)</param> /// <returns>Created lifetime container for the specified object type</returns> public override LifetimeBase Create(Type objType, IInjectionResolver injection, object extInfo) { if (objType == null) { throw new ArgumentNullException(nameof(objType)); } if (injection == null) { throw new ArgumentNullException(nameof(injection)); } var creationFunc = ObjectInstantiationHelper.GetCompiledCreationFunction(objType, extInfo); return(new PerThreadLifetime(creationFunc, objType)); }
/// <summary> /// Creates a SingletonLifetime container that resolves an instance of the specified object type /// </summary> /// <param name="objType">The type of the object that will be held by the lifetime container</param> /// <param name="injection">Injection resolver that will be used to create an instance if required</param> /// <param name="extInfo">Extended information supplied by the user (can be null)</param> /// <returns>Created lifetime container for the specified object type</returns> public override LifetimeBase Create(Type objType, IInjectionResolver injection, object extInfo) { if (objType == null) { throw new ArgumentNullException(nameof(objType)); } if (injection == null) { throw new ArgumentNullException(nameof(injection)); } var obj = ObjectInstantiationHelper.CreateObject(objType, injection, extInfo); return(new SingletonLifetime(obj)); }
/// <summary> /// Creates a PerCallInlinedParamsInterfaceLifetime container that resolves an instance of the specified object type /// </summary> /// <param name="objType">The type of the object that will be held by the lifetime container</param> /// <param name="injection">Injection resolver that will be used to create an instance if required</param> /// <param name="extInfo">Extended information supplied by the user (can be null)</param> /// <returns>Created lifetime container for the specified object type</returns> public override LifetimeBase Create(Type objType, IInjectionResolver injection, object extInfo) { if (objType == null) { throw new ArgumentNullException(nameof(objType)); } if (injection == null) { throw new ArgumentNullException(nameof(injection)); } var creationObj = ObjectInstantiationHelper.BuildInstanceCreatorNoParamInDynAssembly(objType, injection, extInfo); return(new PerCallInlinedParamsInterfaceLifetime(objType, creationObj)); }
/// <summary> /// Creates an instance of an object of type 'T' using the default constructor /// </summary> /// <typeparam name="T">The type of the object to be created</typeparam> /// <param name="resolver">Injection source</param> /// <returns>Created object</returns> public static T CreateObject <T>(IInjectionResolver resolver) { Contract.Requires(resolver != null); return((T)ObjectInstantiationHelper.CreateObject(typeof(T), resolver, null)); }
/// <summary> /// Creates an instance of an object of 'objType' type using the parameterless constructor /// </summary> /// <param name="objType">The type of the object to be created</param> /// <returns>Created object</returns> public static object CreateObject(Type objType) { Contract.Requires(objType != null); return(ObjectInstantiationHelper.CreateObject(objType)); }
/// <summary> /// Creates a PerCallInterfaceLifetime container that resolves an instance of the specified object type /// </summary> /// <param name="objType">The type of the object that will be held by the lifetime container</param> /// <param name="injection">Injection resolver that will be used to create an instance if required</param> /// <param name="extInfo">Extended information supplied by the user (can be null)</param> /// <returns>Created lifetime container for the specified object type</returns> public override LifetimeBase Create(Type objType, IInjectionResolver injection, object extInfo) { var creationObj = ObjectInstantiationHelper.BuildInstanceCreatorInDynAssembly(objType, extInfo); return(new PerCallInterfaceLifetime(objType, creationObj)); }
/// <summary> /// Creates a PerThreadLifetime container that resolves an instance of the specified object type /// </summary> /// <param name="objType">The type of the object that will be held by the lifetime container</param> /// <param name="injection">Injection resolver that will be used to create an instance if required</param> /// <param name="extInfo">Extended information supplied by the user (can be null)</param> /// <returns>Created lifetime container for the specified object type</returns> public override LifetimeBase Create(Type objType, IInjectionResolver injection, object extInfo) { var creationFunc = ObjectInstantiationHelper.GetCompiledCreationFunction(objType, extInfo); return(new PerThreadLifetime(creationFunc, objType)); }
/// <summary> /// Creates a DeferedSingletonLifetime container that resolves an instance of the specified object type /// </summary> /// <param name="objType">The type of the object that will be held by the lifetime container</param> /// <param name="injection">Injection resolver that will be used to create an instance if required</param> /// <param name="extInfo">Extended information supplied by the user (can be null)</param> /// <returns>Created lifetime container for the specified object type</returns> public override LifetimeBase Create(Type objType, IInjectionResolver injection, object extInfo) { var creationFunc = ObjectInstantiationHelper.GetReflectionBasedCreationFunction(objType, extInfo); return(new DeferedSingletonLifetime(creationFunc, objType)); }
/// <summary> /// Creates a SingletonLifetime container that resolves an instance of the specified object type /// </summary> /// <param name="objType">The type of the object that will be held by the lifetime container</param> /// <param name="injection">Injection resolver that will be used to create an instance if required</param> /// <param name="extInfo">Extended information supplied by the user (can be null)</param> /// <returns>Created lifetime container for the specified object type</returns> public override LifetimeBase Create(Type objType, IInjectionResolver injection, object extInfo) { var obj = ObjectInstantiationHelper.CreateObject(objType, injection, extInfo); return(new SingletonLifetime(obj)); }