SmartDIContainer.cs
/// <summary>
/// Removes a bound instance from all shared instances. Also cleans up any orphaned shared instances.
/// </summary>
/// <param name="obj">The object.</param>
Removes a bound instance from all shared instances. Also cleans up any orphaned shared instances.
Removes a bound instance from all shared instances . Also cleans up any orphaned shared instances .
protected void RemoveBoundSharedDependencies(object obj)
      {
         if (_sharedInstancesWithBoundMembers.IsEmpty())
         {
            return;
         }
         var sharedInstancesIndexesToDelete = new List<int>();
         for (var sharedInstanceIdx = 0;
              sharedInstanceIdx < _sharedInstancesWithBoundMembers.Count;
              sharedInstanceIdx++)
         {
            var keyToSeek         = _sharedInstancesWithBoundMembers.Keys.ToList()[sharedInstanceIdx];
            var sharedInstance    = _sharedInstancesWithBoundMembers[keyToSeek];
            var foundBoundMembers = sharedInstance.Where(si => ReferenceEquals(si, obj)).ToArray();
            if (!foundBoundMembers.Any())
            {
               continue;
            }
            foreach (var foundBoundMember in foundBoundMembers)
            {
               sharedInstance.Remove(foundBoundMember);
            }
            if (sharedInstance.IsEmpty())
            {
               sharedInstancesIndexesToDelete.Add(sharedInstanceIdx);
            }
         }
         foreach (var sharedInstanceIdx in sharedInstancesIndexesToDelete.ToArray())
         {
            var keyToSeek = _sharedInstancesWithBoundMembers.Keys.ToList()[sharedInstanceIdx];
            _sharedInstancesWithBoundMembers.Remove(keyToSeek);
         }
      }
protected void RemoveBoundSharedDependencies ( object obj ) { if ( _sharedInstancesWithBoundMembers . IsEmpty ( ) ) { return ; } var sharedInstancesIndexesToDelete = new List < int > ( ) ; for ( var sharedInstanceIdx = 0 ; sharedInstanceIdx < _sharedInstancesWithBoundMembers . Count ; sharedInstanceIdx ++ ) { var keyToSeek = _sharedInstancesWithBoundMembers . Keys . ToList ( ) [ sharedInstanceIdx ] ; var sharedInstance = _sharedInstancesWithBoundMembers [ keyToSeek ] ; var foundBoundMembers = sharedInstance . Where ( si => ReferenceEquals ( si , obj ) ) . ToArray ( ) ; if ( ! foundBoundMembers . Any ( ) ) { continue ; } foreach ( var foundBoundMember in foundBoundMembers ) { sharedInstance . Remove ( foundBoundMember ) ; } if ( sharedInstance . IsEmpty ( ) ) { sharedInstancesIndexesToDelete . Add ( sharedInstanceIdx ) ; } } foreach ( var sharedInstanceIdx in sharedInstancesIndexesToDelete . ToArray ( ) ) { var keyToSeek = _sharedInstancesWithBoundMembers . Keys . ToList ( ) [ sharedInstanceIdx ] ; _sharedInstancesWithBoundMembers . Remove ( keyToSeek ) ; } }
Removes a bound instance from all shared instances.
Removes a bound instance from all shared instances .
// If the shared instance is empty, it must be removed, but best to do so after this iteration. // Remove the shared instances that are now orphaned // This has been revised, so will fail on removal
obj
object
None