예제 #1
0
 protected virtual void Upsert(DomainEvent domainEvent)
 {
     if (ThisRecordHasBeenInserted(domainEvent))
         Update(domainEvent);
     else
         Insert(domainEvent);
 }
예제 #2
0
 private static IDomainEventMessage CreateDomainEventMessage(DomainEvent domainEvent)
 {
     var domainEventMessageType = typeof(DomainEventMessage<>).MakeGenericType(domainEvent.GetType());
     var message = (IDomainEventMessage)Activator.CreateInstance(domainEventMessageType);
     message.DomainEvent = domainEvent;
     return message;
 }
예제 #3
0
        public void PublishEvent(DomainEvent domainEvent)
        {
            if(!eventHandlerInvokers.ContainsKey(domainEvent.GetType())) return;

            var eventHandlerInvoker = eventHandlerInvokers[domainEvent.GetType()];
            eventHandlerInvoker.Publish(domainEvent);
        }
예제 #4
0
 public void Apply(DomainEvent domainEvent)
 {
     domainEvent.Sequence = ++LastEventSequence;
     ApplyEventToInternalState(domainEvent);
     domainEvent.AggregateRootId = Id;
     domainEvent.EventDate = DateTime.Now;
     uncommittedEvents.Enqueue(domainEvent);
 }
예제 #5
0
        private void ApplyEventToEntities(DomainEvent domainEvent)
        {
            var entityDomainEvent = domainEvent as EntityDomainEvent;
            if (entityDomainEvent == null) return;

            var list = _entities.Where(entity => entity.Id == entityDomainEvent.EntityId).ToList();
            list.ForEach(entity => entity.ApplyHistoricalEvents(entityDomainEvent));
        }
예제 #6
0
 private static Dictionary<string, object> BuildADataObjectThatHasAllUpdatableData(DomainEvent domainEvent,
     IEnumerable<string> tableColumnsToUpdate)
 {
     var dictionary = new Dictionary<string, object>();
     foreach (var property in tableColumnsToUpdate)
         dictionary[property] = GetValue(domainEvent, property);
     dictionary["Id"] = domainEvent.AggregateRootId;
     return dictionary;
 }
 public string Serialize(DomainEvent domainEvent) {
     var formatter = new BinaryFormatter();
     using (var stream = new MemoryStream()) {
         formatter.Serialize(stream, domainEvent);
         stream.Flush();
         stream.Position = 0;
         return Convert.ToBase64String(stream.ToArray());
     }
 }
예제 #8
0
 public void Publish(DomainEvent domainEvent)
 {
     var handleMethod = typeof(IHandleDomainEvents<>).MakeGenericType(domainEventType).GetMethod("Handle");
     foreach (var eventHandlerType in eventHandlerTypes)
     {
         var eventHandler = eventHandlerFactory.Create(eventHandlerType);
         handleMethod.Invoke(eventHandler, new object[] {domainEvent});
     }
 }
        public void PublishEvent(DomainEvent domainEvent)
        {
            var domainEventType = domainEvent.GetType();
            var invokers = (from entry in eventHandlerInvokers
                           where  entry.Key.IsAssignableFrom(domainEventType)
                           select entry.Value).ToList();

            invokers.ForEach(i => i.Publish(domainEvent));
        }
예제 #10
0
        public void PublishEvent(DomainEvent domainEvent)
        {
            while (eventConverters.ContainsKey(domainEvent.GetType()))
                domainEvent = ((dynamic)eventConverterFactory.Create(eventConverters[domainEvent.GetType()])).Convert((dynamic)domainEvent);

            if(!eventHandlerInvokers.ContainsKey(domainEvent.GetType())) return;

            var eventHandlerInvoker = eventHandlerInvokers[domainEvent.GetType()];
            eventHandlerInvoker.Publish(domainEvent);
        }
예제 #11
0
        private void ApplyEventToInternalState(DomainEvent domainEvent)
        {
            var domainEventType = domainEvent.GetType();
            var domainEventTypeName = domainEventType.Name;
            var aggregateRootType = GetType();

            var methodInfo = aggregateRootType.GetMethod(GetEventHandlerMethodName(domainEventTypeName),
                                                         BindingFlags.Instance | BindingFlags.Public |
                                                         BindingFlags.NonPublic, null, new[] {domainEventType}, null);

            if(methodInfo == null || !EventHandlerMethodInfoHasCorrectParameter(methodInfo, domainEventType)) return;

            methodInfo.Invoke(this, new[] {domainEvent});
        }
예제 #12
0
        private void ApplyEventToInternalState(DomainEvent domainEvent)
        {
            //
            // TODO: cache handler method
            //
            var domainEventType = domainEvent.GetType();
            var domainEventTypeName = domainEventType.Name;
            var aggregateRootType = GetType();

            var eventHandlerMethodName = GetEventHandlerMethodName(domainEventTypeName);
            var methodInfo = aggregateRootType.GetMethod(eventHandlerMethodName,
                BindingFlags.Instance | BindingFlags.Public |
                BindingFlags.NonPublic, null, new[] {domainEventType}, null);

            if (methodInfo != null && EventHandlerMethodInfoHasCorrectParameter(methodInfo, domainEventType))
            {
                methodInfo.Invoke(this, new[] {domainEvent});
            }

            ApplyEventToEntities(domainEvent);
        }
예제 #13
0
            public void Publish(DomainEvent domainEvent)
            {
                var exceptionList = new List<Exception>();

                var handleMethod = typeof(IHandleDomainEvents<>).MakeGenericType(domainEventType).GetMethod("Handle");
                foreach(var eventHandlerType in eventHandlerTypes)
                {
                    try
                    {
                        var eventHandler = eventHandlerFactory.Create(eventHandlerType);
                        handleMethod.Invoke(eventHandler, new object[] {domainEvent});
                    }
                    catch(Exception exception)
                    {
                        logger.Error(string.Format("An exception occured while handling event of type '{0}'\nMessage: {1}", domainEvent.GetType(), exception.Message), exception);
                        exceptionList.Add(exception);
                    }
                }

                if(exceptionList.Count > 0)
                    throw new AggregateException(exceptionList);
            }
예제 #14
0
 private bool ThisRecordHasBeenInserted(DomainEvent domainEvent)
 {
     return (bool) TheDatabaseTable.FindAllById(domainEvent.AggregateRootId).Any();
 }
 public string Serialize(DomainEvent domainEvent)
 {
     return JsonSerializer.SerializeToString(domainEvent, domainEvent.GetType());
 }
예제 #16
0
 public static void Modify(DomainEvent e)
 {
     if (Modification != null)
         Modification.Apply(e);
 }
예제 #17
0
 public void PublishEvent(DomainEvent domainEvent)
 {
     Bus.Publish<IDomainEventMessage>(message => message.DomainEvent = domainEvent);
 }
예제 #18
0
        protected virtual void Insert(DomainEvent domainEvent)
        {
            var data = GetTheDataToUpdateInTheTable(domainEvent);

            TheDatabaseTable.Insert(data);
        }
 public EventStoreConcurrencyException(int latestVersion, DomainEvent domainEvent, List<DomainEvent> domainEventsList)
 {
     LatestVersion = latestVersion;
     DomainEventInstance = domainEvent;
     DomainEventsList = domainEventsList;
 }
예제 #20
0
 private IDictionary<string, object> GetTheDataToUpdateInTheTable(DomainEvent domainEvent)
 {
     return (updateValuesBuilder.GetTheDataToUpdateInTheTable(domainEvent, tableName));
 }
예제 #21
0
 public void PublishEvent(DomainEvent domainEvent)
 {
     serviceBus.Notify(domainEvent);
 }
예제 #22
0
 public async Task PublishEvent(SimpleCqrs.Eventing.DomainEvent domainEvent)
 {
     await _serviceBus.PublishAsync((IEvent)domainEvent).ConfigureAwait(false);
 }
예제 #23
0
 private IEnumerable<string> GetTheTableColumnsThatNeedToBeUpdated(DomainEvent domainEvent, string tableName)
 {
     return domainEvent.GetType().GetProperties()
         .Select(x => x.Name)
         .Where(property => GetTheColumnsInTheTable(tableName).Contains(property));
 }
예제 #24
0
 protected void Delete(DomainEvent domainEvent)
 {
     TheDatabaseTable.DeleteById(domainEvent.AggregateRootId);
 }
예제 #25
0
 public void Apply(DomainEvent e)
 {
     if (e is EventForModificationTestEvent)
         ((EventForModificationTestEvent)e).ModifiedValue = ModifyValueTo;
 }
예제 #26
0
        public IDictionary<string, object> GetTheDataToUpdateInTheTable(DomainEvent domainEvent, string tableName)
        {
            var tableColumnsToUpdate = GetTheTableColumnsThatNeedToBeUpdated(domainEvent, tableName);

            return BuildADataObjectThatHasAllUpdatableData(domainEvent, tableColumnsToUpdate);
        }
예제 #27
0
        protected virtual void Update(DomainEvent domainEvent)
        {
            var data = GetTheDataToUpdateInTheTable(domainEvent);

            TheDatabaseTable.UpdateById(data);
        }
예제 #28
0
 public void PublishEvent(DomainEvent domainEvent)
 {
     _bus.Publish(domainEvent);
 }
예제 #29
0
 private static object GetValue(DomainEvent domainEvent, string column)
 {
     return GetThePropertyOnThisObject(domainEvent, column).GetValue(domainEvent, null);
 }