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

198 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Sebastian WeberSebastian Weber shared this idea  ·   ·  Admin →

    4 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Rory PrimroseRory Primrose commented  · 

        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 SorensenBill Sorensen commented  · 

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

      • SFenceSFence commented  · 

        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.

      • JeffJeff commented  · 

        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