Ejemplo n.º 1
0
        protected async Task SaveAggregateAsync(TAggregate aggregate)
        {
            Aggregate.Changeset changeset = aggregate.GetChangeset();
            foreach (AggregateEvent @event in changeset.Events)
            {
                await _eventStore.AddEventAsync(@event);
            }
            changeset.Commit();

            AggregateSaved?.Invoke(this, new AggregateSavedEventArgs(changeset.Events));
        }
 public void GenericBaseTargetEventPublished()
 {
     using (var scope = BeginScope())
     {
         var @event = new AggregateSaved <Aggregate>(new Person());
         scope.PublishEvent(@event);
         var aggregateEventHandler = scope.Resolve <AggregateEventHandler>();
         var aggregateSavedHandler = scope.Resolve <AggregateSavedHandler>();
         Assert.NotNull(aggregateEventHandler.LastEvent);
         Assert.NotNull(aggregateSavedHandler.LastEvent);
     }
 }
Ejemplo n.º 3
0
 protected virtual Task OnAggregateSavedAsync(
     TAggregate aggregate,
     CancellationToken?cancellationToken = default)
 {
     return(AggregateSaved.PassiveInvokeAsync(
                this,
                new AggregateSavedAsyncEventArgs <TAggregate>(aggregate, cancellationToken: cancellationToken),
                onFailure: failure => OnDiagnosticsEmittedAsync(
                    Level.Warning,
                    cancellationToken: cancellationToken,
                    cause: failure,
                    message: RepositoryOnAggregateSavedAsyncFailure)));
 }
 public void GenericDerivedTargetNotPublished()
 {
     using (var scope = BeginScope())
     {
         var @event = new AggregateSaved <Person>(new Person());
         scope.PublishEvent(@event);
         var aggregateEvent = scope.Resolve <AggregateEventHandler>();
         var aggregateSaved = scope.Resolve <AggregateSavedHandler>();
         var personEvent    = scope.Resolve <PersonEventHandler>();
         var personSaved    = scope.Resolve <PersonSavedHandler>();
         Assert.Null(aggregateEvent.LastEvent);
         Assert.Null(aggregateSaved.LastEvent);
         Assert.NotNull(personEvent.LastEvent);
         Assert.NotNull(personSaved.LastEvent);
     }
 }