开发者

Castle Windsor and creating instances as a factory

开发者 https://www.devze.com 2023-02-19 06:10 出处:网络
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.

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...

  1. Create an interface (which we'll call IFactory) with a method like CreateFoo();
  2. Register the IFactory interface with Spring but configured so that it knows to treat it like a factory.
  3. In your class ask for IFactory which spring will of course provide you with.
  4. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消