title: Implementing a custom event handler from interface
body: <p>I am in the process of creating a system that can receive messages from a variety of different sources.</p>
  
  <p>Using the <code>interface</code> approach, I am adding a custom event which will pass the message back to the calling application.</p>
  
  <p>I've used Vistual Studio's "scaffolding" using <code>Ctrl-.</code> to provide the implementation for the concrete class, but its added the <code>add</code> and <code>remove</code> elements but I dont really know how to wire that bit up.</p>
  
  <p><strong>Interface class</strong></p>
  
  <pre><code>public class MessageEventArgs : EventArgs
  {
      public Message { get; set; }
  }
  
  public interface MessageBroker
  {
      void Start();
  
      event EventHandler&lt;MessageEventArgs&gt; OnMessageReceived;
  }
  </code></pre>
  
  <p><strong>Implementation class</strong></p>
  
  <pre><code>public class MessageSourceA : MessageBroker
  {
      event EventHandler&lt;MessageEventArgs&gt; MessageBroker.OnMessageReceived
      {
          add
          {
              // What goes here
          }
  
          remove
          {
              // What goes here
          }
      }
  
      void MessageBroker.Start()
      {
      }
  }
  </code></pre>
  
  <p><strong>Main Program</strong></p>
  
  <pre><code>    static void Main(string[] args)
      {
          MessageBroker sourceA = new MessageSourceA ();
          sourceA.OnMessageReceived += sourceA_OnMessageReceived;
      }
  
      private static void sourceA_OnMessageReceived(object sender, MessageEventArgs e)
      {
          // Do stuff with message
      }
  </code></pre>
  
  <p>Thanks...</p>