예제 #1
0
        public Task <ProductAggregate?> Handle(ESauceEvent evt, AddProductsEvent payload, ProductAggregate?prevState)
        {
            var agg = prevState ?? new ProductAggregate();

            agg.Quantity += payload.Amount;

            return(Task.FromResult(agg) !);
        }
예제 #2
0
        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 ! };
예제 #3
0
 public async Task AddEvent <T>(Guid aggregateId, T payload)
 {
     var evt = ESauceEvent.Create(aggregateId, payload);
     await eventRepository.AddEvent(evt);
 }