c# - LifetimeManager in Builder Strategy -


i want implement disposing transient lifetime manager unity version 3.5. problem don't know how access lifetimemanager in postteardown,etc. steps of builderstrategy class. context.lifetime works fine in unity 2.

basically have following:

container = new unitycontainer(); container.addnewextension<disposablestrategyextension>(); container.registertype<itest, test>(new disposingtransientlifetimemanager());   public class disposinglifetimestrategy : builderstrategy     {         public override void prebuildup(ibuildercontext context)         {             base.prebuildup(context);             // context.lifetime.count == 0 here , in other methods.             // in version 2 of unity set.         }     // implement rest of methods, context.lifetime.count 0 in of them too.   public class disposingtransientlifetimemanager : lifetimemanager     // implement abstract methods minimally 

you can lifetime manager policy list:

public class disposinglifetimestrategy : builderstrategy {     public override void prebuildup(ibuildercontext context)     {         ilifetimepolicy lifetime = context.policies.get<ilifetimepolicy>(context.buildkey);                        base.prebuildup(context);     }      public override void preteardown(ibuildercontext context)     {         // assumes registration name null         var buildkey = new namedtypebuildkey(context.existing.gettype());         ilifetimepolicy lifetime = context.policies.get<ilifetimepolicy>(buildkey);         base.preteardown(context);     } } 

if calling iunitycontainer.teardown(obj) preteardown , postteardown methods not know name of resolved object. may not matter long default (null) registration exists (since assume want cast object idisposable , dispose object).


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -