Hi there, 
        
The issue IOC-ISSUE-208 was just created by Gilles Bisson (Gilles Bisson).
        
        Key: IOC-ISSUE-208
        Summary: Bad dispose order of a singleton object with a dependency on a 
transcient object
        Type: Bug
        Importance: High
        
        Description:
        When a singleton object depends on a transcient object, disposal order 
of the two objects is wrong upon container disposal.
The following test illustrate this behavior :
  public class DisposeOrderTestFixture
  {
    interface IMyService : IInitializable, IDisposable
    {
      bool IsInitialized { get; }
      bool IsInUse { get; set; }
    }
    interface IMyComponent : IInitializable, IDisposable
    {
      bool IsInitialized { get; }
    }
    class MyService : IMyService
    {
      #region
      private bool m_isInUse;
      #endregion
      #region IMyService Members
      public bool IsInitialized { get; private set; }
      public bool IsInUse
      {
        get
        {
          if(IsInitialized == false)
          {
            throw new ApplicationException("Service must be initialized !!!");
          }
          return m_isInUse;
        }
        set
        {
          if (IsInitialized == false)
          {
            throw new ApplicationException("Service must be initialized !!!");
          }
          m_isInUse = value;
        }
      }
      #endregion
      #region IInitializable Members
      public void Initialize()
      {
        IsInitialized = true;
      }
      #endregion
      #region IDisposable Members
      public void Dispose()
      {
        if(IsInUse)
        {
          throw new ApplicationException("Cannot dispose : service is still in 
use !!!");
        }
        IsInitialized = false;
      }
      #endregion
    }
    class MyComponent : IMyComponent
    {
      #region Attributes
      private readonly IMyService m_service;
      #endregion
      #region Constructor
      public MyComponent(IMyService service)
      {
        m_service = service;
      }
      #endregion
      #region IMyComponent Members
      public bool IsInitialized { get; private set; }
      #endregion
      #region IInitializable Members
      public void Initialize()
      {
        m_service.IsInUse = true;
        IsInitialized = true;
      }
      #endregion
      #region IDisposable Members
      public void Dispose()
      {
        IsInitialized = false;
        m_service.IsInUse = false;
      }
      #endregion
    }
    class MyInstaller : IWindsorInstaller
    {
      #region IWindsorInstaller Members
      public void Install(IWindsorContainer container, IConfigurationStore 
store)
      {
        
container.Register(Component.For<IMyService>().ImplementedBy<MyService>().LifeStyle.Transient);
        
container.Register(Component.For<IMyComponent>().ImplementedBy<MyComponent>());
      }
      #endregion
    }
    [Test]
    public void ShouldDisposeComponentsInProperOrder()
    {
      var installer = new MyInstaller();
      var container = new WindsorContainer();
      container.Install(installer);
      var component = container.Resolve<IMyComponent>();
      container.Release(component);
      container.Dispose();
    }
  }
        
For more, see 
http://support.castleproject.org/projects/IOC/issues/view/IOC-ISSUE-208
 
        
--
donjon
by Castle Stronghold
http://www.castle-donjon.com


-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Development List" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-devel?hl=en.

Reply via email to