private async Task LaunchEventHandlers(IAggregate aggregate, ITeclynEvent @event) { var eventTypeAncestors = @event.GetType().GetAllAncestorsAndInterfaces(); var handlers = eventTypeAncestors .SelectMany(ancestorType => this._eventHandlerService.GetEventHandlers(ancestorType)) .Select(handler => handler.GetHandleAction(aggregate, @event)); await Task.WhenAll(handlers.Select(t => t())); }
private IEventInformation BuildEventInformation(ITeclynEvent @event) { var eventInformation = new EventInformation(); eventInformation.Id = this.IdGenerator.GenerateId(); eventInformation.User = this._teclynContext.CurrentUser; eventInformation.Date = this._timeService.Now(); eventInformation.EventType = @event.GetType().ToString(); eventInformation.Event = @event; return(eventInformation); }
public void Inject(ITeclynEvent @event) { var properties = @event.GetType().GetRuntimeProperties().Where(property => property.CanWrite); var injectionActions = properties .Select(property => new { Injector = injectors.FirstOrDefault(injector => injector.AppliesToProperty(property)), Property = property }) .Where(info => info.Injector != null) .Select(info => (Action)(() => info.Injector.Inject(@event, info.Property))); foreach (var injectionAction in injectionActions) { injectionAction(); } }
public Func <Task> GetHandleAction(IAggregate aggregate, ITeclynEvent @event) { return(() => this.action(aggregate, @event)); }
public void Inject(ITeclynEvent @event, PropertyInfo property) { property.SetValue(@event, this.dataBuilder()); }