protected virtual void Upsert(DomainEvent domainEvent) { if (ThisRecordHasBeenInserted(domainEvent)) Update(domainEvent); else Insert(domainEvent); }
private static IDomainEventMessage CreateDomainEventMessage(DomainEvent domainEvent) { var domainEventMessageType = typeof(DomainEventMessage<>).MakeGenericType(domainEvent.GetType()); var message = (IDomainEventMessage)Activator.CreateInstance(domainEventMessageType); message.DomainEvent = domainEvent; return message; }
public void PublishEvent(DomainEvent domainEvent) { if(!eventHandlerInvokers.ContainsKey(domainEvent.GetType())) return; var eventHandlerInvoker = eventHandlerInvokers[domainEvent.GetType()]; eventHandlerInvoker.Publish(domainEvent); }
public void Apply(DomainEvent domainEvent) { domainEvent.Sequence = ++LastEventSequence; ApplyEventToInternalState(domainEvent); domainEvent.AggregateRootId = Id; domainEvent.EventDate = DateTime.Now; uncommittedEvents.Enqueue(domainEvent); }
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)); }
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()); } }
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)); }
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); }
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}); }
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); }
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); }
private bool ThisRecordHasBeenInserted(DomainEvent domainEvent) { return (bool) TheDatabaseTable.FindAllById(domainEvent.AggregateRootId).Any(); }
public string Serialize(DomainEvent domainEvent) { return JsonSerializer.SerializeToString(domainEvent, domainEvent.GetType()); }
public static void Modify(DomainEvent e) { if (Modification != null) Modification.Apply(e); }
public void PublishEvent(DomainEvent domainEvent) { Bus.Publish<IDomainEventMessage>(message => message.DomainEvent = domainEvent); }
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; }
private IDictionary<string, object> GetTheDataToUpdateInTheTable(DomainEvent domainEvent) { return (updateValuesBuilder.GetTheDataToUpdateInTheTable(domainEvent, tableName)); }
public void PublishEvent(DomainEvent domainEvent) { serviceBus.Notify(domainEvent); }
public async Task PublishEvent(SimpleCqrs.Eventing.DomainEvent domainEvent) { await _serviceBus.PublishAsync((IEvent)domainEvent).ConfigureAwait(false); }
private IEnumerable<string> GetTheTableColumnsThatNeedToBeUpdated(DomainEvent domainEvent, string tableName) { return domainEvent.GetType().GetProperties() .Select(x => x.Name) .Where(property => GetTheColumnsInTheTable(tableName).Contains(property)); }
protected void Delete(DomainEvent domainEvent) { TheDatabaseTable.DeleteById(domainEvent.AggregateRootId); }
public void Apply(DomainEvent e) { if (e is EventForModificationTestEvent) ((EventForModificationTestEvent)e).ModifiedValue = ModifyValueTo; }
public IDictionary<string, object> GetTheDataToUpdateInTheTable(DomainEvent domainEvent, string tableName) { var tableColumnsToUpdate = GetTheTableColumnsThatNeedToBeUpdated(domainEvent, tableName); return BuildADataObjectThatHasAllUpdatableData(domainEvent, tableColumnsToUpdate); }
protected virtual void Update(DomainEvent domainEvent) { var data = GetTheDataToUpdateInTheTable(domainEvent); TheDatabaseTable.UpdateById(data); }
public void PublishEvent(DomainEvent domainEvent) { _bus.Publish(domainEvent); }
private static object GetValue(DomainEvent domainEvent, string column) { return GetThePropertyOnThisObject(domainEvent, column).GetValue(domainEvent, null); }