/// <summary> /// Disposes the object. /// </summary> /// <param name="disposing"><see langword="true"/> when the user code is disposing; /// <see langword="false"/> when it is the GC. /// </param> protected virtual void Dispose(bool disposing) { if (disposing) { _builder.TearDown(_locator, this); if (_parent != null) { List <object> ids = new List <object>(); foreach (KeyValuePair <object, object> pair in _parent.Locator) { if (pair.Value == this) { ids.Add(pair.Key); } } foreach (object id in ids) { _parent.Locator.Remove(id); } _parent._lifetime.Remove(this); } _lifetime.Remove(this); List <object> lifetimeObjects = new List <object>(); lifetimeObjects.AddRange(_lifetime); foreach (object obj in lifetimeObjects) { if (_lifetime.Contains(obj)) { _builder.TearDown(_locator, obj); } } _lifetime.Dispose(); } }
private object Build(Type typeToBuild, Type typeToRegisterAs, object serviceInstance) { Guard.TypeIsAssignableFromType(typeToBuild, typeToRegisterAs, "typeToBuild"); if (locator.Contains(new DependencyResolutionLocatorKey(typeToRegisterAs, null), SearchMode.Local)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.DuplicateService, typeToRegisterAs.FullName)); } if (serviceInstance == null) { serviceInstance = BuildFirstTimeItem(typeToBuild, typeToRegisterAs, null); } else if (!container.Contains(serviceInstance)) { serviceInstance = BuildFirstTimeItem(typeToBuild, typeToRegisterAs, serviceInstance); } else { BuildRepeatedItem(typeToRegisterAs, serviceInstance); } return(serviceInstance); }
/// <summary> /// Determines if the collection contains an object. /// </summary> /// <param name="item">The object.</param> /// <returns>Returns true if the collection contains the object; false otherwise.</returns> public bool ContainsObject(TItem item) { return(container.Contains(item)); }
/// <summary> /// See <see cref="ILifetimeContainer.Contains"/>. /// </summary> bool ILifetimeContainer.Contains(object item) { return(lifetime.Contains(item)); }
/// <summary> /// Determines if the collection contains an object. /// </summary> /// <param name="item">The object.</param> /// <returns>Returns true if the collection contains the object; false otherwise.</returns> public bool ContainsObject(TItem item) { return(_lifetimeContainer.Contains(item)); }