Castle Windsor and instantiation as factory

I need to get N instances of an object where I won’t know N until launch, but I am also trying to avoid container calls inside my own code.

In Spring, you do the following ...

  • Create an interface (which we will call IFactory) using a method such as CreateFoo ();
  • Register the IFactory interface with Spring, but configure it so that it knows it as a factory.
  • In your class, ask for IFactory, which Spring will certainly provide for you.
  • Call CreateFoo () for IFactory. Spring will intercept your call and create an instance of Foo for you.

Does anyone know if this is possible in Windsor and how will I do it? Or even some way to achieve my goal (get N copies of something WITHOUT talking directly to the container).

Thanks!

+4
source share
1 answer

Yes, Windsor Castle has a factory-typed object to address this particular scenario.

+6
source

Source: https://habr.com/ru/post/1345095/


All Articles