国际奥委会的打断链 [英] Interrupted chain of IoC

查看:103
本文介绍了国际奥委会的打断链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立它使用一个抽象工厂模式,让这我IHardwareDevice的子类来创建基于它是如何回应的鉴定请求在运行时确定的应用程序。我可能会创建Hardware1或Hardware2。

I am building an application which uses an Abstract Factory pattern to allow runtime determination of which subclass of my IHardwareDevice to create based upon how it responds to a request for identification. I might create Hardware1 or Hardware2.

的问题,即出现我想用这些IHardwareDevice对象国的模式,我想有国家由国际奥委会来创建容器。有没有为此而不直接调用IoC容器,以解决与滋润IHardwareDevice国家物体的好办法?

The problem arises in that I want to use a State pattern in these IHardwareDevice objects and I want to have the State be created by the IoC container. Is there a good way to do this without directly calling the IoC container to resolve the State objects with which to hydrate the IHardwareDevice?

或者,我在想着这在错误的方法?由于我厂是相当多的入口点到这个库中,什么情况下可以有这个厂处理实例化容器在图书馆用?我打算让客户端应用程序实例化的容器,然后用它来获得它需要的库不断部位,如工厂。

Or, am I thinking about this in the wrong way? Because my Factory is pretty much the entry point into this library, is it okay to have this Factory handle instantiating the container for use in the library? I was planning on having the client application instantiate the container and then use it to gain access to which ever parts of the library it requires, such as the Factory.

我规划中的项目,如果需要切换使用温莎作为IoC容器,但我在早期足够的舞台。

I am planning to use Windsor as the IoC container, but am at an early enough stage in the project to switch if needed.

推荐答案

温莎具有自动实现抽象工厂一个非常强大的工具 - 类型化的工厂设备

Windsor has a very powerful facility for auto-implementing abstract factories - Typed Factory Facility

这在很大程度上是基于惯例,如果默认的约定不能满足您的需求,您可以通过提供定制覆盖它 ITypedFactoryComponentSelector

It is largely convention based, and if the default convention does not suit your needs, you can override it by providing custom ITypedFactoryComponentSelector.

通过它可以访问所有的信息,你可能需要作出决定 - 要传下去调用车道什么内嵌的论点,哪些组件,您要解决的问题。

It gives you access to all information you may need to make the decision - what inline arguments you want to pass down the invocation lane, and what component you want to resolve.

这篇关于国际奥委会的打断链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆