开发者

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

  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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜