/// <summary> /// Removes an object from the container. /// </summary> /// <param name="item">The item to be removed.</param> public void Remove(TItem item) { if (container.Contains(item)) { ThrowIfItemRemovalIsNotPermitted(item); builder.TearDown(locator, item); container.Remove(item); List <object> keysToRemove = new List <object>(); foreach (KeyValuePair <object, object> pair in locator) { if (pair.Value.Equals(item)) { keysToRemove.Add(pair.Key); } } foreach (object key in keysToRemove) { locator.Remove(key); } } }
/// <summary> /// Removes a service registration from the <see cref="WorkItem"/>. /// </summary> /// <param name="serviceType">The service type to remove.</param> public void Remove(Type serviceType) { Guard.ArgumentNotNull(serviceType, "serviceType"); DependencyResolutionLocatorKey key = new DependencyResolutionLocatorKey(serviceType, null); if (locator.Contains(key, SearchMode.Local)) { object serviceInstance = locator.Get(key, SearchMode.Local); bool isLastInstance = true; locator.Remove(new DependencyResolutionLocatorKey(serviceType, null)); foreach (KeyValuePair <object, object> kvp in locator) { if (ReferenceEquals(kvp.Value, serviceInstance)) { isLastInstance = false; break; } } if (isLastInstance) { builder.TearDown(locator, serviceInstance); container.Remove(serviceInstance); if (!(serviceInstance is DemandAddPlaceholder)) { OnRemoved(serviceInstance); } } } }
public bool Remove(object key) { object item = Get(key); container.Remove(item); return(Decoratee.Remove(key)); }
public void OnDisposed(object sender, EventArgs e) { locator.Remove(key); ILifetimeContainer lifetime = locator.Get <ILifetimeContainer>(); if (lifetime != null) { lifetime.Remove(sender); } }
/// <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(); } }
/// <summary> /// See <see cref="ILifetimeContainer.Remove"/>. /// </summary> void ILifetimeContainer.Remove(object item) { lifetime.Remove(item); }