public object CreateInstance(IInjectionResolver resolver) { TurboContract.Requires(resolver != null, conditionString: "resolver != null"); TurboContract.Ensures(TurboContract.Result <object>() != null); throw new NotImplementedException(); }
public object CreateInstance(IInjectionResolver resolver) { Contract.Requires(resolver != null); Contract.Ensures(Contract.Result <object>() != null); throw new NotImplementedException(); }
/// <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)); }
/// <summary> /// Creates a new instance for the current thread and stores it inside '_obj' /// </summary> /// <param name="resolver">Injection resolver to acquire parameters</param> /// <returns>Created instance</returns> private ThreadLocalSlot CreateInstanceCore(IInjectionResolver resolver) { var result = new ThreadLocalSlot(_createInstFunc(resolver)); _obj.Value = result; return(result); }
public override object GetInstance(IInjectionResolver resolver) { Contract.Requires(resolver != null); Contract.Ensures((Contract.Result <object>() != null && Contract.Result <object>().GetType() == this.OutputType) || (Contract.Result <object>() == null && this.OutputType.IsAssignableFromNull())); throw new NotImplementedException(); }
public override object GetInstance(IInjectionResolver resolver) { TurboContract.Requires(resolver != null, conditionString: "resolver != null"); TurboContract.Ensures((TurboContract.Result <object>() != null && TurboContract.Result <object>().GetType() == this.OutputType) || (TurboContract.Result <object>() == null && this.OutputType.IsAssignableFromNull())); throw new NotImplementedException(); }
/// <summary> /// Resolves the object held by the container /// </summary> /// <param name="resolver">Injection resolver to acquire parameters</param> /// <returns>Resolved instance of the object</returns> /// <exception cref="CommonIoCException">Can be raised when injections not found</exception> public sealed override object GetInstance(IInjectionResolver resolver) { if (!_isInited) { CreateInstanceCore(resolver); } return(_obj); }
public override LifetimeBase Create(Type objType, IInjectionResolver injection, object extInfo) { Contract.Requires <ArgumentNullException>(objType != null, "objType != null"); Contract.Requires <ArgumentNullException>(injection != null, "injection != null"); Contract.Ensures(Contract.Result <LifetimeBase>() != null); Contract.Ensures(Contract.Result <LifetimeBase>().OutputType == objType); throw new NotImplementedException(); }
/// <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)); }
public override LifetimeBase Create(Type objType, IInjectionResolver injection, object extInfo) { TurboContract.Requires(objType != null, conditionString: "objType != null"); TurboContract.Requires(injection != null, conditionString: "injection != null"); TurboContract.Ensures(TurboContract.Result <LifetimeBase>() != null); TurboContract.Ensures(TurboContract.Result <LifetimeBase>().OutputType == objType); throw new NotImplementedException(); }
/// <summary> /// Sets required objects when the current instance was created by the parameterless constructor /// </summary> /// <param name="injection">Injection container</param> /// <param name="association">Association container</param> /// <param name="resolver">Injection resolver</param> protected void SetInnerObjects(TInjection injection, TAssociation association, IInjectionResolver resolver) { Contract.Requires(injection != null); Contract.Requires(association != null); Contract.Requires(resolver != null); _injection = injection; _association = association; _resolver = resolver; }
/// <summary> /// ObjectLocator constructor /// </summary> /// <param name="injection">Injection container</param> /// <param name="association">Association container</param> /// <param name="resolver">Injection resolver</param> protected ObjectLocator(TInjection injection, TAssociation association, IInjectionResolver resolver) { Contract.Requires(injection != null); Contract.Requires(association != null); Contract.Requires(resolver != null); _injection = injection; _association = association; _resolver = resolver; }
/// <summary> /// Sets required objects when the current instance was created by the parameterless constructor /// </summary> /// <param name="injection">Injection container</param> /// <param name="association">Association container</param> /// <param name="resolver">Injection resolver</param> protected void SetInnerObjects(TInjection injection, TAssociation association, IInjectionResolver resolver) { TurboContract.Requires(injection != null, conditionString: "injection != null"); TurboContract.Requires(association != null, conditionString: "association != null"); TurboContract.Requires(resolver != null, conditionString: "resolver != null"); _injection = injection; _association = association; _resolver = resolver; }
/// <summary> /// Core method to create an instance of an object (separated to improve the performance) /// </summary> /// <param name="resolver">Injection resolver to acquire parameters</param> private void CreateInstanceCore(IInjectionResolver resolver) { lock (_lockObj) { if (!_isInited) { _obj = _createInstanceFunc(resolver); _isInited = true; } } }
/// <summary> /// Resolves the object held by the container /// </summary> /// <param name="resolver">Injection resolver to acquire parameters</param> /// <returns>Resolved instance of the object</returns> /// <exception cref="CommonIoCException">Can be raised when injections not found</exception> public sealed override object GetInstance(IInjectionResolver resolver) { var result = _obj.Value; if (!result.IsInitialized) { result = CreateInstanceCore(resolver); } return(result.Object); }
/// <summary> /// Resolves the object held by the container /// </summary> /// <param name="resolver">Injection resolver to acquire parameters</param> /// <returns>Resolved instance of the object</returns> /// <exception cref="CommonIoCException">Can be raised when injections not found</exception> public sealed override object GetInstance(IInjectionResolver resolver) { TurboContract.Requires(resolver != null, conditionString: "resolver != null"); if (!_isInited) { CreateInstanceCore(resolver); } return(_obj); }
/// <summary> /// Resolves the object held by the container /// </summary> /// <param name="resolver">Injection resolver to acquire parameters</param> /// <returns>Resolved instance of the object</returns> /// <exception cref="CommonIoCException">Can be raised when injections not found</exception> public sealed override object GetInstance(IInjectionResolver resolver) { TurboContract.Requires(resolver != null, conditionString: "resolver != null"); var result = _obj.Value; if (!result.IsInitialized) { result = CreateInstanceCore(resolver); } return(result.Object); }
/// <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> /// CommonObjectLocator constructor /// </summary> /// <param name="useAssocAsDISource">Allows object injection from the IoC container itself (not only from InjectionContainer)</param> /// <param name="disposeInjectionWithBuilder">Indicates whether the all injected objects should be disposed with the container</param> public CommonObjectLocator(bool useAssocAsDISource, bool disposeInjectionWithBuilder) { _disposeInjectionWithBuilder = disposeInjectionWithBuilder; _useAssocAsDISource = useAssocAsDISource; _injection = new TypeStrictInjectionContainer(_disposeInjectionWithBuilder); if (_useAssocAsDISource) { _resolver = new InjectionThenAssociationResolver(_injection, this); } else { _resolver = _injection.GetDirectInjectionResolver(); } _association = new AssociationContainer(_resolver); }
/// <summary> /// Attempts to resolve the object held by the container. /// Resolution can fail when required injection objects not found /// </summary> /// <param name="resolver">Injection resolver to acquire parameters</param> /// <param name="val">Resolved instance of the object</param> /// <returns>True if the object was successfully resolved</returns> public bool TryGetInstance(IInjectionResolver resolver, out object val) { TurboContract.Requires(resolver != null, conditionString: "resolver != null"); TurboContract.Ensures((TurboContract.Result <bool>() == true && ((TurboContract.ValueAtReturn(out val) != null && TurboContract.ValueAtReturn(out val).GetType() == this.OutputType) || (TurboContract.ValueAtReturn(out val) == null && this.OutputType.IsAssignableFromNull()))) || (TurboContract.Result <bool>() == false && TurboContract.ValueAtReturn(out val) == null)); try { val = GetInstance(resolver); return(true); } catch (CommonIoCException) { } catch (KeyNotFoundException) { } val = null; return(false); }
/// <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> /// Resolves the object held by the container /// </summary> /// <param name="resolver">Injection resolver to acquire parameters</param> /// <returns>Resolved instance of the object</returns> /// <exception cref="CommonIoCException">Can be raised when injections not found</exception> public sealed override object GetInstance(IInjectionResolver resolver) { return(_obj); }
/// <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> /// SimpleObjectLocator constructor /// </summary> public SimpleObjectLocator() { _resolver = new InnerInjectionResolver(this); }
/// <summary> /// Resolves the object held by the container /// </summary> /// <param name="resolver">Injection resolver to acquire parameters</param> /// <returns>Resolved instance of the object</returns> /// <exception cref="CommonIoCException">Can be raised when injections not found</exception> public sealed override object GetInstance(IInjectionResolver resolver) { TurboContract.Requires(resolver != null, conditionString: "resolver != null"); return(_createInstanceObj.CreateInstance(resolver)); }
/// <summary> /// Resolves the object held by the container /// </summary> /// <param name="resolver">Injection resolver to acquire parameters</param> /// <returns>Resolved instance of the object</returns> /// <exception cref="CommonIoCException">Can be raised when injections not found</exception> public sealed override object GetInstance(IInjectionResolver resolver) { return(_createInstanceObj.CreateInstance()); }
/// <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)); }