【问题标题】:implement plugable channel to a C# interface将可插入通道实现到 C# 接口
【发布时间】:2013-11-27 05:43:27
【问题描述】:

假设我有一个接口 IMyComponent,我想直接或通过 WCF 或其他通信渠道调用它,我应该如何设计它?

我的想法:

将其拆分为提供者和消费者部分:

IMyComponentProvider: IMyComponent
IMyComponentConsumer: IMyComponent

并构建一个将这两个接口连接在一起的对象:

MyComponent (MyComponentProvider)

问题:

  • 有哪些替代方案,尤其是使用 autofac?
  • 哪种设计模式适用于此以及替代方案?
  • 哪些命名约定有用或标准?

【问题讨论】:

  • 也许这是“责任链”?

标签: c# interface communication autofac channel


【解决方案1】:

AFAIK 没有针对此问题的通用解决方案。这并不是真正的“责任链”,因为您不想让任何参与者有机会处理此请求。 但它可以松散地被视为“过滤器链”。

Autofac 的问题在于您已经注册了组件并构建了 Autofac 容器,然后才能使用它。以后无法解决组件并注册替换。

如果你知道你的链,你可以为它注册特殊的接口: 注册(IComponent,ComponentType) Register(IComponentChannel, ComponentChannelType) 这就像您的提供者/消费者模式。

或者,您必须使用通道装饰您的组件并注册装饰的界面。 寄存器(IComponent, ChannelDecorator))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-30
    相关资源
    最近更新 更多