Project Description
The Binder automatically connects output-pins to input-pins of Event-Based Components based on message type information and naming conventions.

Like a DI Container it makes component orientied programming a lot easier.

What are Event-Based Components?
Event-Based Components (EBC) firstly are software components meaning they are binary units of code described by an explicit contract.

In addition EBC restrict themselves to purely message oriented communication. Consider two EBCs called C and S which are connected like this:

C -> S

C sends messages, and S receives those messages. EBC send messages via so called output pins, and they received messages via so called input pins. If two EBCs are connected that means their output and input pins are wire together.

How does that look in code? Here are the contracts for the above EBC:

interface Ic
{
  event Action<string> OnX;
}

interface Is
{
  void ProcessX(string x);
}
Note that the pins are restricted to just 1 parameter that is going to carry the messages.

Now consider these implementations:

class C : Ic
{
  public void Run(string text)
  {
    this.OnX(text);
  }

  public event Action<string> OnX;
}

class S : Is
{
  public void ProcessX(string x)
  {
    Console.WriteLine(x);
  }
}
To get instances of these EBC types working together, they need to be build and bound:

// Build
Is s = new S();
Ic c = new C();

// Bind
c.OnX += s.ProcessX;

// Run
c.Run("hello, world!");
What does the EBC Binder do?
The Binder automates wiring-up EBC. It relieves you of connecting the potentially many output and input pins of your EBC.
Regarding the above example this would look like so:

using ebc.componentbinder;
...
// Bind
new ComponentBinder().Bind(c, s);
Just pass in all the components needed to be wired-up and let the binder do the magic. It matches output to input pins based on message types and event/event-handler names. Don´t forget to check the ebc.componentbinder.log file it generates. It contains a list of all pins wired-up during Bind().

Naming convention for output pins (events): Prefix the event description with "On", e.g. "OnCompilationRequest".
Naming convention for input pins (event handlers): Prefix the event description with "Process" or "Handle", e.g. "ProcessCompilationRequest".

Easy Interception
With the EBC Binder it´s easy to intercept all messages sent between components. Just pass a listener method to Bind():

new ComponentBinder().Bind(new object[] {c, s}, msg => Console.WriteLine(msg));
Currently this is just a very simple means to inject code into the communication between components. But still it shows what´s easily possible with EBCs. No DynamicProxy rocket science is necessary to listen on conversations. At least as long as they are flowing along permanent connections set up by the Binder. That´s a start, isn´t it?

Further Reading
For more information on the EBC idea see these articles (currently only in German):
If you don´t understand German at least have a look at the code and the pictures in those articles ;-)

Last edited Mar 1, 2010 at 4:37 PM by ralfw, version 16