public T Resolve <T>() { Lifetime.LifetimeBase life = null; if (!this.TryGetAssociation(typeof(T), out life)) { ThrowObjectCannotBeResolvedException(typeof(T)); } Debug.Assert(life != null); return((T)life.GetInstance(this)); }
public bool TryResolve <T>(out T val) { Lifetime.LifetimeBase life = null; if (this.TryGetAssociation(typeof(T), out life)) { Debug.Assert(life != null); val = (T)life.GetInstance(this); return(true); } val = default(T); return(false); }
/// <summary> /// Resolves the object of the specified type ('reqObjectType') to be injected to the constructor of another type ('forType') /// </summary> /// <param name="reqObjectType">The type of the object to be resolved</param> /// <param name="paramName">The name of the parameter to that the injection will be performed (can be null)</param> /// <param name="forType">The type of the object to be created (can be null)</param> /// <param name="extData">Extended information supplied by the user (can be null)</param> /// <returns>Resolved instance to be injected</returns> object IInjectionResolver.Resolve(Type reqObjectType, string paramName, Type forType, object extData) { if (reqObjectType == null) { throw new ArgumentNullException("reqObjectType", "Requested object type cannot be null"); } Lifetime.LifetimeBase life = null; if (!this.TryGetAssociation(reqObjectType, out life)) { throw new ObjectCannotBeResolvedException(string.Format("Object of type {0} cannot be resolved by IoC container. That object is required as the parameter ({2}) to create another object of type {1}.", reqObjectType, forType, paramName)); } Debug.Assert(life != null); return(life.GetInstance(this)); }
public object Resolve(Type key) { Contract.Requires(key != null); if (key == null) { ThrowKeyNullException(); } Lifetime.LifetimeBase life = null; if (!this.TryGetAssociation(key, out life)) { ThrowObjectCannotBeResolvedException(key); } Debug.Assert(life != null); return(life.GetInstance(this)); }
public bool TryResolve(Type key, out object val) { Contract.Requires((object)key != null); Lifetime.LifetimeBase life = null; if (this.TryGetAssociation(key, out life)) { Debug.Assert(life != null); if (life.TryGetInstance(_resolver, out val)) { return(true); } } val = null; return(false); }
public bool TryResolve(TAssocKey key, out object val) { TurboContract.Requires(key != null, conditionString: "key != null"); Lifetime.LifetimeBase life = null; if (_association.TryGetAssociation(key, out life)) { TurboContract.Assert(life != null, conditionString: "life != null"); if (life.TryGetInstance(_resolver, out val)) { return(true); } } val = null; return(false); }
public bool TryResolve(Type key, out object val) { Contract.Requires(key != null); if (key == null) { ThrowKeyNullException(); } Lifetime.LifetimeBase life = null; if (this.TryGetAssociation(key, out life)) { Debug.Assert(life != null); val = life.GetInstance(this); return(true); } val = null; return(false); }
public bool TryResolve <T>(out T val) { Lifetime.LifetimeBase life = null; if (this.TryGetAssociation(typeof(T), out life)) { TurboContract.Assert(life != null, conditionString: "life != null"); if (life.TryGetInstance(_resolver, out object tmp)) { if (tmp is T) { val = (T)tmp; return(true); } } } val = default(T); return(false); }
public bool TryResolve <T>(out T val) { Lifetime.LifetimeBase life = null; if (this.TryGetAssociation(typeof(T), out life)) { Debug.Assert(life != null); object tmp = null; if (life.TryGetInstance(_resolver, out tmp)) { if (tmp is T) { val = (T)tmp; return(true); } } } val = default(T); return(false); }