public String RunIdGetterMethod(AggregateEvent @event) { var method = GetType().GetTypeInfo().DeclaredMethods .Where(m => !m.IsStatic) .Where(x => x.GetParameters().Length == 1) .SingleOrDefault(x => x.GetParameters()[0].ParameterType.GetTypeInfo().IsAssignableFrom(@event.GetType())); return((String)method?.Invoke(this, new[] { @event }) ?? @event.AggregateId); }
public void Apply(AggregateView view, AggregateEvent @event) { var method = GetApplyMethod(@event.GetType()); if (method == null) { throw new Exception($"'{GetType().FullName}' don't know how to apply a '{@event.GetType().FullName}'"); } method.Invoke(this, new Object[] { view, @event }); }
private void Apply(AggregateEvent @event, Boolean isFresh) { if (isFresh) { @event.AggregateId = Id; @event.EventOccurred = DateTime.UtcNow; _changes.Add(@event); } var applier = GetApplierOfConcreteEvent(@event.GetType()); applier?.Invoke(this, new Object[] { @event }); Version++; }
public async Task <Command[]> Handle(AggregateEvent @event) { var methods = GetType().GetTypeInfo().DeclaredMethods .Where(x => !x.IsStatic) .Where(x => x.GetParameters().Length == 1) .Where(x => x.GetParameters()[0].ParameterType == @event.GetType()); var commands = new List <Command>(); foreach (var method in methods) { var cmds = await(Task <Command[]>) method.Invoke(this, new[] { @event }); commands.AddRange(cmds); } return(commands.ToArray()); }