Пример #1
0
        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()));
        }
Пример #2
0
        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);
        }
Пример #3
0
        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();
            }
        }
Пример #4
0
 public Func <Task> GetHandleAction(IAggregate aggregate, ITeclynEvent @event)
 {
     return(() => this.action(aggregate, @event));
 }
Пример #5
0
 public void Inject(ITeclynEvent @event, PropertyInfo property)
 {
     property.SetValue(@event, this.dataBuilder());
 }