Пример #1
0
        internal void ApplyInitialEvent(LoadedEvent @event)
        {
            if (_changes.Any())
            {
                throw new Exception("ApplyInitialEvent can only be used for a new aggregate");
            }

            _changes.Add(@event);
        }
Пример #2
0
        bool IEventApplier.ProcessMessage(LoadedEvent loadedEvent)
        {
            if (_messageHandlerDictionary.TryGetValue(loadedEvent.Data.GetType(), out var handler))
            {
                handler.Execute(loadedEvent);
                return(true);
            }

            return(false);
        }
Пример #3
0
        // push atomic aggregate changes to local history for further processing (EventStore.SaveEvents)
        private void ApplyChange(LoadedEvent @event, bool isNew)
        {
            IEventApplier applier = this;

            applier.ProcessMessage(@event);
            if (isNew)
            {
                _changes.Add(@event);
            }
        }
Пример #4
0
        private TAggregateRoot CreateInternal(LoadedEvent firstLoadedEvent)
        {
            var eventType      = firstLoadedEvent.Data.GetType();
            var typedEventType = typeof(TypedEvent <>).MakeGenericType(eventType);
            var typedEvent     = typedEventType.GetConstructors().First().Invoke(new object[] { firstLoadedEvent.EventDateTime, firstLoadedEvent.Data });

            var constructors = typeof(TAggregateRoot).GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

            if (constructors.Length == 1)
            {
                var constructor = constructors[0];
                if (constructor.IsPrivate)
                {
                    var paramTypes = constructor.GetParameters();
                    if (paramTypes.Length == 1 && paramTypes[0].ParameterType == typedEventType)
                    {
                        return((TAggregateRoot)constructor.Invoke(new object[] { typedEvent }));
                    }
                }
            }

            throw new Exception($"Aggregate {typeof(TAggregateRoot).Name} must have 1 private constructor(TypedEvent<{eventType.Name}> initialEvent)");
        }
Пример #5
0
 internal abstract void Execute(LoadedEvent loadedEvent);