I suggest you ...

Unity Lifetimes: TearDown should dispose objects created by container

TearDown does not do anything with the LifetimeManagers supplied ootb. It should properly dispose object(graph)s created by the container

211 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Sebastian Weber shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

4 comments

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...
  • Rory Primrose commented  ·   ·  Flag as inappropriate

    Bill, you are right that ContainerControlledLifetimeManager does disposal, but there are two issues with it. First, it is only done for that lifetime manager and all other managers don't run any disposal. Second, it only disposes the top level instance, not the entire object graph.

  • Bill Sorensen commented  ·   ·  Flag as inappropriate

    This is not the case. ContainerControlledLifetimeManager disposes instances when the container is disposed.

  • SFence commented  ·   ·  Flag as inappropriate

    Rory Primrose has developed a Unity Extension that seems to do just that, as part of the Neovolve Tookit, and written multiple articles about it (http://www.neovolve.com/post/2010/06/18/Unity-Extension-For-Disposing-Build-Trees-On-TearDown.aspx). I would really love to see this integrated into Unity, as properly disposing the object graph is something a DI container should be able to do. Creating and disposing child containers feels inappropriate in design, and HierarchicalLifetimeManager prevents from using any other lifestyle.

  • Jeff commented  ·   ·  Flag as inappropriate

    I agree. The pattern of creating a child container and disposing it is needlessly complex for what should be a simple Resolve<T>(), Release(x) interface.

Feedback and Knowledge Base