views:

29

answers:

2

I just noticed that the IWindsorContainer interface in Castle Windsor includes Dispose().

None of the CastleWindsor tutorials I have seen (e.g. http://dotnetslackers.com/articles/designpatterns/InversionOfControlAndDependencyInjectionWithCastleWindsorContainerPart1.aspx and http://wiki.bittercoder.com/ContainerTutorials.ashx) declare the container in a using block or call Dispose on it.

Should I be calling Dispose() on my container, or does it depend? If the latter, upon what?

Thanks

David

A: 

The rule is that if something somewhere implements IDisposable, you must dispose of it when you're done with it (and disposing correctly can also prevent objects from being prematurely finalized).

erikkallen
A sensible point, but do you know why the Windsor container needs disposing?
David
No, I don't know Windsor. I guess, however, that disposing the container will dispose any contained disposable element.
erikkallen
A: 

Yes you do.

Krzysztof Koźmic
Looks like it's related to the container's Release method which will be the subject of my next question.
David
So, just to clarify, Disposing of the container calls Dispose (where appropriate) on all the components it has resolved? Is that basically it?
David
I suggest reading this documentation page http://stw.castleproject.org/Windsor.LifeStyles.ashx
Krzysztof Koźmic