title: Simple Injector with Domain Events
body: <p>I'm trying to implement Domain Events into my system, but I'm stuck. I am using SimpleInjector, and I think i'm missing something. </p>
  
  <p>Domain Event:</p>
  
  <pre><code>public static class DomainEvent
  {
      public static IEventDispatcher Dispatcher { get; set; }
  
      public static void Raise&lt;T&gt;(T @event) where T : IDomainEvent
      {
          Dispatcher.Dispatch(@event);
      }
  
  }
  </code></pre>
  
  <p>SimpleInjectorEventDispatcher</p>
  
  <pre><code>public class SimpleInjectorEventDispatcher : IEventDispatcher
  {
      private readonly Container container;
      public SimpleInjectorEventDispatcher(Container container)
      {
          this.container = container;
      }
  
      public void Dispatch&lt;TEvent&gt;(TEvent eventToDispatch) where TEvent : IDomainEvent
      {
          var handlerType = typeof(IDomainHandler&lt;&gt;).MakeGenericType(eventToDispatch.GetType());
          var handlers = this.container.GetAllInstances(handlerType);
  
          foreach (dynamic handler in handlers)
          {
              handler.HandleEvent((dynamic)eventToDispatch);
          }
      }
  }
  </code></pre>
  
  <p>SimpleInjector</p>
  
  <pre><code>container.Register&lt;IEventDispatcher, SimpleInjectorEventDispatcher&gt;();
  </code></pre>
  
  <p>The IEventDispatcher Dispatcher is always null. How do I make sure it is correctly initialised?</p>