/// <summary> /// Invoked through reflection /// </summary> /// <typeparam name="T"></typeparam> /// <param name="command"></param> private void Dispatch <T>(T command) where T : class, ICommand { using (var scope = _rootContainer.CreateScope()) { ScopeStarted(this, new IocScopeEventArgs(scope, command)); scope.Resolve <IHandleCommand <T> >().Invoke(command); ScopeSuccessful(this, new IocScopeEventArgs(scope, command)); } }
/// <summary> /// Invoked through reflection /// </summary> /// <typeparam name="T">Type of event</typeparam> /// <param name="domainEvent">The event that should be dispatched</param> private void Dispatch <T>(T domainEvent) where T : class, IDomainEvent { using (var scope = _rootContainer.CreateScope()) { foreach (var subscriber in scope.ResolveAll <ISubscribeOn <T> >()) { subscriber.Handle(domainEvent); } } }
/// <summary> /// Dispatch the command to the handler /// </summary> /// <typeparam name="T">Type of command</typeparam> /// <param name="command">Command to execute</param> /// <remarks>Implementations should throw exceptions unless they are asynchronous or will attempt to retry later.</remarks> public void Dispatch <T>(T command) where T : class, ICommand { if (command == null) { throw new ArgumentNullException("command"); } using (var scope = _inversionOfControlContainer.CreateScope()) { ScopeStarted(this, new IocScopeEventArgs(scope, command)); scope.Resolve <IHandleCommand <T> >().Invoke(command); ScopeSuccessful(this, new IocScopeEventArgs(scope, command)); } }
/// <summary> /// Dispatch domain event. /// </summary> /// <typeparam name="T">Domain event type</typeparam> /// <param name="domainEvent">The domain event</param> /// <exception cref="System.ArgumentNullException"></exception> public void Dispatch <T>(T domainEvent) where T : class, IDomainEvent { if (domainEvent == null) { throw new ArgumentNullException("domainEvent"); } using (var scope = _container.CreateScope()) { foreach (var handler in scope.ResolveAll <ISubscribeOn <T> >()) { handler.Handle(domainEvent); } } }