Castle Windsor and creating instances as a factory
I need to get N instances of an object where I won't know N until run time BUT I'开发者_Python百科m also trying to avoid any container calls within my own code.
In Spring you would do the following...
- Create an interface (which we'll call IFactory) with a method like CreateFoo();
- Register the IFactory interface with Spring but configured so that it knows to treat it like a factory.
- In your class ask for IFactory which spring will of course provide you with.
- Call CreateFoo() on IFactory. Spring will intercept your call and create an instance of Foo for you.
Does anyone know if this possible in Windsor and how I would go about doing it? Or even some way of accomplishing my goal (get N instances of something WITHOUT talking directly to the container).
Thanks!
Yes, Castle Windsor has the Typed Factory Facility to address exactly this scenario.
精彩评论