Question

Let’s say I have an interface IMyComponent and I want to call it directly or over WCF or some other communication channel how should I deign it?

My idea:

Split this up in a provider and consumer part:

IMyComponentProvider: IMyComponent
IMyComponentConsumer: IMyComponent

And build a object that wires this two interfaces together:

MyComponent (MyComponentProvider) <- Channel( MyComponentConsumer) <- calling context

Questions:

  • What are the alternatives especially with autofac?
  • Which design pattern applies to this and the alternatives?
  • Which naming conventions are useful or standard?
Was it helpful?

Solution

AFAIK there is no generalized solution for this problem. It is not really a "chain of responsibility", because you don't want to give any participant the chance to handle this request. But it can loosely be seen as a "chain of filters".

The problem with Autofac is that you have register your components and build the Autofac container before you can use it. It is not possible to resolve a component and register a replacement later.

If you know your chain, you can register special interfaces for it: Register( IComponent, ComponentType ) Register(IComponentChannel, ComponentChannelType) this is like your provider / consumer pattern.

Alternatively you must decorate your component with the channel and register the decorated interface. Register( IComponent, ChannelDecorator) )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top