开发者

Automatic release of objects when using Castle Windsor

开发者 https://www.devze.com 2023-02-17 15:48 出处:网络
I\'m starting a new project and I\'m looking into using a dependency container (Castle Windsor) to help when it comes to unit testing. One of the things that is a little frustrating is that after I\'v

I'm starting a new project and I'm looking into using a dependency container (Castle Windsor) to help when it comes to unit testing. One of the things that is a little frustrating is that after I've finished using an object I have to tell the container to "release" the object.

I understand the reasoning behind doing this, but it's still cumbersome to have to remember to do this. So, my question is, is there a way I can make the "releasing" of an object automatic so I don't have to remember to release it开发者_开发百科?


You should apply the Register Resolve Release pattern in the application's Composition Root.

You should release what you create, but since you should only have a single line of code that resolves objects, you'll also only need a single line of code that releases those objects.

In other words, you don't have to remember anything because once you have that little piece of infrastructure in place, you should never have to think about it again.

0

精彩评论

暂无评论...
验证码 换一张
取 消