Does RemoveValue Get Called By Unity

Nov 16, 2009 at 6:35 PM

Hi,

I'm about to create a pooled lifetime manager similar to how Windsor provides for an object pool, I was originally thinking that GetValue essentially pulled the item from the value pool and RemoveValue would pop it back into the pool; however, after reading Chris Tavares' blog entry http://www.tavaresstudios.com/Blog/post/Writing-Custom-Lifetime-Managers.aspx which states that RemoveValue isn't ever called by Unity, I'm left wondering how the lifetime manager can get informed that the object can be placed back into the pool.

What's the best approach to take?

Thanks in advance,

Carlos

Nov 16, 2009 at 7:42 PM

Unity does not call RemoveValue directly. What you'll need to do is have a combination of a lifetime manager and an ObjectBuilder strategy as part of your pooling extension. Then, when you call container.Teardown(obj) you can use your strategy to pop the object back into the pool. Actually, you might not even need the lifetime manager at all now that I think about it.

 

Nov 16, 2009 at 9:12 PM
Edited Nov 16, 2009 at 9:16 PM

Thx for the pointer...

So would I create a subclass of LifetimeStrategy and just override the Pre/PostTearDown methods? If so, how do I go about registering my LifetimeStrategy with ObjectBuilder?

Now that I think about it...Wouldn't I need a LifetimeManager so that I can associate that only specific types are pooled or can you associate an object build strategy with specific types?

Thx again,

Carlos