public void Apply(EntityDomainEvent domainEvent) { domainEvent.EntityId = Id; if (!((IHaveATestMode) this).IsInTestMode) AggregateRoot.Apply(domainEvent); _uncommittedEvents.Enqueue(domainEvent); ApplyEventToInternalState(domainEvent); }
// // TODO: Cache event handler // private void ApplyEventToInternalState(EntityDomainEvent domainEvent) { var domainEventType = domainEvent.GetType(); var domainEventTypeName = domainEventType.Name; var entityType = GetType(); var methodInfo = entityType.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}); }