For some context, I'm working with Windsor and asp.net webapi.  There's a 
webapicontrib project that provides what is effectively a controllerfactory 
(in this case an IDependencyResolver) that is implements its scopes by 
using a child container. Specifically, each request is handled by a child 
container that is then disposed at the end of the request.  All my 
registrations are done at the parent level.

Now, onto the problem.

What I was expecting is that once the child container was disposed, all the 
transient components that were resolved via that container would be 
disposed as well (if my controller had some dependencies that were 
IDisposable I would expect them to get disposed).  In fact, nothing gets 
disposed.  If I debug, I see that the components are actually listed under 
the _parent's_ "Objects tracked by release policy" and nothing is tracked 
at the child level at all.  Since the parent scope lives for the life of 
the app, those bits are never cleaned up.

Am I misunderstanding how child containers are supposed to work?

Here's a very brief sample.  "Disposed" is never printed.

interface ITest
    {        
    }

    class Tester : ITest, IDisposable
    {
        public Tester()
        {
            Console.WriteLine("Created");
        }
     
        public void Dispose()
        {
            Console.WriteLine("Disposed");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var parent = new WindsorContainer();
            
parent.Register(Component.For<ITest>().ImplementedBy<Tester>().LifestyleTransient());

            var child = new WindsorContainer();
            parent.AddChildContainer(child);

            var i = child.Resolve<ITest>();

            child.Dispose();

            Console.WriteLine("Done");
            Console.ReadLine();
        }
    }

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to castle-project-users+unsubscr...@googlegroups.com.
To post to this group, send email to castle-project-users@googlegroups.com.
Visit this group at http://groups.google.com/group/castle-project-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to