示例#1
0
        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);
        }
示例#2
0
        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 });
        }
示例#3
0
        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++;
        }
示例#4
0
        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());
        }