public Task <ProductAggregate?> Handle(ESauceEvent evt, AddProductsEvent payload, ProductAggregate?prevState) { var agg = prevState ?? new ProductAggregate(); agg.Quantity += payload.Amount; return(Task.FromResult(agg) !); }
private async Task <TAggregate?> Apply(ESauceEvent evt, TAggregate?prevState) { var handlerType = handlerMappingProvider.FindHandlerForEvent(evt.PayloadType); var handler = serviceProvider.GetService(handlerType); if (handler == null) { throw new Exception($"No IEventProcessor found to process event of type {evt.PayloadType}"); } const string methodName = nameof(IEventHandler <object, AggregateBase> .Handle); var processMethod = handler.GetType().GetMethod(methodName); var methodParameters = new[] { evt, evt.Payload !, prevState ! };
public async Task AddEvent <T>(Guid aggregateId, T payload) { var evt = ESauceEvent.Create(aggregateId, payload); await eventRepository.AddEvent(evt); }