Problem with resource managment

Dec 28, 2010 at 4:46 PM

Hi,

I'm read in the book "Dependency Injection in .NET" that one of Unity's relative weaknesses is that resource management can become difficult because components are not properly released after use.

Is this true?

In addition it say that we can implement custom lifetime that address these issue. Has anyone do something like this? How diffucult it can be?

This is important to my company because we are evaluating various DI Containers to choose one.

Thanks!

Dec 30, 2010 at 7:25 PM

You're misreading the book. The author considers resource management in Unity weak not because it doesn't work, but because the "out of the box" lifetimes is a fairly small set (and due to a bug he hit). I know, I reviewed the Unity chapter. Lifetime managers are called at the appropriate time and do clean up objects when that time comes. Just using container controlled / hierarchical lifetimes and child containers can handle the vast majority of lifetime requirements in a straightforward manner.

Creating a new lifetime manager is actually pretty straightforward, I know there's a full and complete example in the book.

Is your evaluation, you shouldn't just have a "lifetime management" checkbox. Instead, figure out what you're actually going to need, and evaluate each container on that feature, not on a general feature name that could mean many different things to different people or organizations.