private async Task DispatchEvent <TEvent>(TEvent @event, CancellationToken cancellationToken) { using (IServiceScope serviceScope = _serviceScopeFactory.CreateScope()) { IEnumerable <IEventHandler <TEvent> > handlers = serviceScope.GetServices <IEventHandler <TEvent> >(); foreach (IEventHandler <TEvent> handler in handlers ?? Enumerable.Empty <IEventHandler <TEvent> >()) { await handler.Handle(@event, cancellationToken).ConfigureAwait(false); } } }