Question

I have a simple diagram editor, and after reading books on IoC and DI, I decided to try to decouple my code with help that they provides. It looks like when user add diagram item to diagram, item is created by abstract factory and added to internal diagrams list of items. But what to do where user whants to delete item from diargam? First i should delete item from internal list. Then i have some misunderstanding on sould i IoC.Release(Item) or not? If I do not call IoC.Release(Item) (avoiding any knowledge of IoC inside my objects), what happend with Item inside IoC.

PS: I am trying to use Castle Windsor

Was it helpful?

Solution

When you create a component using an abstract facility(which I assume is implemented using the Windsor TypeFactory) you component will not be garbage collected if you don't release them. The components can be release by either of :

  1. Creating a Release method on you abstract factory. This method should take one argument (usually object) and a void return type. Calling this method will release the created component.
  2. Releasing the factory. This will release all components created by the factory.

In generally it is a bad idea to call the container directly. Only call the container directly to:

  1. Setup the container.
  2. Resolve your top level component.
  3. Dispose of the container (and all components inside)

I hope this helps.

Kind regards, Marwijn.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top