假设我有一个接口IMyComponent,我想直接或通过WCF或其他通信渠道调用它我应该如何设计它?
我的想法:
将其拆分为提供者和消费者部分:
IMyComponentProvider: IMyComponent
IMyComponentConsumer: IMyComponent
构建一个将这两个接口连接在一起的对象:
MyComponent(MyComponentProvider)< - Channel(MyComponentConsumer)< - 调用上下文
问题:
答案 0 :(得分:1)
AFAIK没有针对此问题的通用解决方案。它并不是一个真正的责任链,因为你不想给任何参与者提供处理这个请求的机会。 但它可以被宽泛地视为过滤器链#34;。
Autofac的问题在于您已经注册了组件并构建了Autofac容器,然后才能使用它。以后无法解析组件并注册替换。
如果你知道你的链,你可以为它注册特殊的接口: 注册(IComponent,ComponentType) 注册(IComponentChannel,ComponentChannelType)这就像你的提供者/消费者模式。
或者,您必须使用通道装饰组件并注册装饰界面。 注册(IComponent,ChannelDecorator))