public SqlCommandScheduler(
     Func <IEventSourcedRepository <TAggregate> > getRepository,
     Func <CommandSchedulerDbContext> createCommandSchedulerDbContext,
     IEventBus eventBus,
     CommandPreconditionVerifier commandPreconditionVerifier)
 {
     if (getRepository == null)
     {
         throw new ArgumentNullException("getRepository");
     }
     if (createCommandSchedulerDbContext == null)
     {
         throw new ArgumentNullException("createCommandSchedulerDbContext");
     }
     if (eventBus == null)
     {
         throw new ArgumentNullException("eventBus");
     }
     if (commandPreconditionVerifier == null)
     {
         throw new ArgumentNullException("commandPreconditionVerifier");
     }
     this.getRepository = getRepository;
     this.createCommandSchedulerDbContext = createCommandSchedulerDbContext;
     this.eventBus = eventBus;
     this.commandPreconditionVerifier = commandPreconditionVerifier;
     consequenter = Consequenter.Create <IScheduledCommand <TAggregate> >(e =>
     {
         Task.Run(() => Schedule(e)).Wait();
     });
 }
Пример #2
0
 public EventHandlerWrapper(IHaveConsequencesWhen <TEvent> consequenter)
 {
     if (consequenter == null)
     {
         throw new ArgumentNullException(nameof(consequenter));
     }
     InnerHandler   = consequenter;
     IsConsequenter = true;
     handle         = (@event, handler) => consequenter.HaveConsequences(@event);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="InMemoryCommandScheduler{TAggregate}"/> class.
        /// </summary>
        /// <param name="repository">The repository.</param>
        /// <exception cref="System.ArgumentNullException">repository</exception>
        public InMemoryCommandScheduler(IEventSourcedRepository <TAggregate> repository)
        {
            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }
            this.repository = repository;

            consequenter = Consequenter.Create <IScheduledCommand <TAggregate> >(e => Schedule(e).Wait());
        }
Пример #4
0
        public static IHaveConsequencesWhen <TEvent> Named <TEvent>(this IHaveConsequencesWhen <TEvent> consequenter, string name)
            where TEvent : IEvent
        {
            var named = consequenter as AnonymousConsequenter <TEvent>;

            if (named == null)
            {
                throw new NotImplementedException($"Handlers of type {consequenter} do not support naming yet.");
            }

            named.Name = name;

            return(consequenter);
        }
Пример #5
0
 internal static IDisposable SubscribeConsequences <TEvent>(
     IHaveConsequencesWhen <TEvent> handler,
     IObservable <TEvent> observable,
     IEventBus bus)
     where TEvent : IEvent => observable
 .Subscribe(
     onNext : e =>
 {
     try
     {
         handler.HaveConsequences(e);
     }
     catch (Exception exception)
     {
         var error = new EventHandlingError(exception, handler, e);
         bus.PublishErrorAsync(error).Wait();
     }
 },
     onError: exception => bus.PublishErrorAsync(new EventHandlingError(exception, handler))
     .Wait());