/// <summary> /// RegisterType an instance with the container. /// </summary> /// <remarks> /// <para> /// Instance registration is much like setting a type as a singleton, except that instead /// of the container creating the instance the first time it is requested, the user /// creates the instance ahead of type and adds that instance to the container. /// </para> /// </remarks> /// <param name="t">Type of instance to register (may be an implemented interface instead of the full type).</param> /// <param name="instance">Object to returned.</param> /// <param name="name">Name for registration.</param> /// <param name="lifetime"> /// <para>If true, the container will take over the lifetime of the instance, /// calling Dispose on it (if it's <see cref="IDisposable"/>) when the container is Disposed.</para> /// <para> /// If false, container will not maintain a strong reference to <paramref name="instance"/>. User is reponsible /// for disposing instance, and for keeping the instance from being garbage collected.</para></param> /// <returns>The <see cref="UnityContainer"/> object that this method was called on (this in C#, Me in Visual Basic).</returns> public IUnityContainer RegisterInstance(Type t, string name, object instance, LifetimeManager lifetime) { Guard.ArgumentNotNull(instance, "instance"); Guard.ArgumentNotNull(lifetime, "lifetime"); Guard.InstanceIsAssignable(t, instance, "instance"); registeringInstance(this, new RegisterInstanceEventArgs(t, instance, name, lifetime)); return(this); }
// FxCop warning suppressed: false positive, Guard class is doing validation public object BuildUp(Type t, object existing, string name, params ResolverOverride[] resolverOverrides) { Guard.ArgumentNotNull(existing, "existing"); Guard.InstanceIsAssignable(t, existing, "existing"); return(DoBuildUp(t, existing, name, resolverOverrides)); }