How to release components resolved using a CollectionResolver?

13 views
Skip to first unread message

Vinay Mandy

unread,
Aug 23, 2011, 1:53:47 PM8/23/11
to Castle Project Users
Hi All,

I have a case where I have to resolve all instances of a specific type
of component. I know that I can use the CollectionResolver class and
then do something like:

var myComponentList = container.Resolve<IList<MyComponent>>();

However, I was unable to find any examples of how to release these
components once I'm done with them. Is it as simple as the following:

container.Release(myComponentList);

Or do I have to manually release them all individually:

foreach (var component in myComponentList)
{
container.Release(component);
}


As a follow-up question, what would be the correct 'release' procedure
if I had used a TypeFactory to resolve the collection, would a
'release' method like the one below work:

interface IMyComponentFactory
{
IList<MyComponent> CreateAllMyComponents();

void DestroyAllMyComponents(IList<MyComponent> components);
}

Thanks in advance for your help.

Jason Meckley

unread,
Aug 23, 2011, 2:26:35 PM8/23/11
to castle-pro...@googlegroups.com
you release each component, not the collection itself. same is true for a typed factory.
Reply all
Reply to author
Forward
0 new messages