title: Event Bus implementation question
body: <p>I'm trying to implement simple Event Bus</p>
  
  <p>I started like this:</p>
  
  <pre><code>public class RegistrationData
  {
      public object RegisteredObject { get; set; }
      public Type eventType { get; set; }
      public EventHandler MethodToInvoke;
  }
  public class EventBus
  {
      private static EventBus instance;
      private static readonly object lockObject = new object();
      private static List&lt;RegistrationData&gt; registrationList;
  
      private EventBus()
      {
      }
  
      public static EventBus Instance
      {
          get
          {
              lock (lockObject)
              {
                  registrationList = new List&lt;RegistrationData&gt;();
                  return instance ?? new EventBus();
              }
          }
      }
  
      public void Subscribe(RegistrationData registrationData)
      {
          if(!registrationList.Contains(registrationData)) registrationList.Add(registrationData);
      }
  
      public void Unsubscribe(object objectToUnregister, Type eventType)
      {
          foreach(RegistrationData data in registrationList)
              if (data.RegisteredObject == objectToUnregister &amp;&amp; data.eventType == eventType) registrationList.Remove(data);
      }
  
      public void UnregisterAllMessages(object objectToUnregister)
      {
          foreach(RegistrationData data in registrationList)
              if(data.RegisteredObject == objectToUnregister) registrationList.Remove(data);
      }
  
      public void PublishEvent(object sender, EventArgs eventArgs)
      {
          foreach (RegistrationData data in registrationList)
              if (EventArgs is typeof(data.Type)) data.MethodToInvoke(sender, eventArgs);
      }
  }
  </code></pre>
  
  <p>But I have problem in PublishEvent method. I'm unable to determine type of event argument.
  And I'm suspicious that all this is pretty wrong.</p>
  
  <p>Can someone point out what I do wrong, how should I implement this?
  Or how event bus is generally implemented, or some framework which I can use instead of implementing my own and spending time on that.</p>