public IEnumerable <DomainEventHandler> GetWrappedHandlers(BaseDomainEvent domainEvent)
        {
            Type        handlerType = typeof(IHandle <>).MakeGenericType(domainEvent.GetType());
            Type        wrapperType = typeof(DomainEventHandler <>).MakeGenericType(domainEvent.GetType());
            IEnumerable handlers    = (IEnumerable)_container.Resolve(typeof(IEnumerable <>).MakeGenericType(handlerType));
            IEnumerable <DomainEventHandler> wrappedHandlers = handlers.Cast <object>()
                                                               .Select(handler => (DomainEventHandler)Activator.CreateInstance(wrapperType, handler));

            return(wrappedHandlers);
        }
Exemple #2
0
        public void Dispatch(BaseDomainEvent domainEvent)
        {
            Type        handlerType = typeof(IHandle <>).MakeGenericType(domainEvent.GetType());
            Type        wrapperType = typeof(DomainEventHandler <>).MakeGenericType(domainEvent.GetType());
            IEnumerable handlers    = (IEnumerable)_container.GetService(typeof(IEnumerable <>).MakeGenericType(handlerType));
            IEnumerable <DomainEventHandler> wrappedHandlers = handlers.Cast <object>()
                                                               .Select(handler => (DomainEventHandler)Activator.CreateInstance(wrapperType, handler));

            foreach (DomainEventHandler handler in wrappedHandlers)
            {
                handler.Handle(domainEvent);
            }
        }
Exemple #3
0
        public async Task Dispatch(BaseDomainEvent domainEvent)
        {
            Type        handlerType = typeof(IHandle <>).MakeGenericType(domainEvent.GetType());
            Type        wrapperType = typeof(DomainEventHandler <>).MakeGenericType(domainEvent.GetType());
            IEnumerable handlers    = (IEnumerable)_container.Resolve(typeof(IEnumerable <>).MakeGenericType(handlerType));
            IEnumerable <DomainEventHandler> wrappedHandlers = handlers.Cast <object>()
                                                               .Select(handler => (DomainEventHandler)Activator.CreateInstance(wrapperType, handler));

            foreach (DomainEventHandler handler in wrappedHandlers)
            {
                await handler.Handle(domainEvent).ConfigureAwait(false);
            }
        }
Exemple #4
0
        public void Dispatch(BaseDomainEvent domainEvent)
        {
            Type        handlerType = typeof(IHandle <>).MakeGenericType(domainEvent.GetType());            //GuestbookNotificationHandler : IHandle<EntryAddedEvent>,获取到事件处理的实际类,即GuestbookNotificationHandler
            Type        wrapperType = typeof(DomainEventHandler <>).MakeGenericType(domainEvent.GetType()); //DomainEventHandler<>的具体类
            IEnumerable handlers    = (IEnumerable)_container.Resolve(typeof(IEnumerable <>).MakeGenericType(handlerType));
            IEnumerable <DomainEventHandler> wrappedHandlers = handlers.Cast <object>()
                                                               .Select(handler => (DomainEventHandler)Activator.CreateInstance(wrapperType, handler));

            foreach (DomainEventHandler handler in wrappedHandlers)
            {
                handler.Handle(domainEvent);
            }
        }
        public void Dispatch(BaseDomainEvent domainEvent)
        {
            var handlerType     = typeof(IHandle <>).MakeGenericType(domainEvent.GetType());
            var wrapperType     = typeof(DomainEventHandler <>).MakeGenericType(domainEvent.GetType());
            var handlers        = _container.GetAllInstances(handlerType);
            var wrappedHandlers = handlers
                                  .Cast <object>()
                                  .Select(handler => (DomainEventHandler)Activator.CreateInstance(wrapperType, handler));

            foreach (var handler in wrappedHandlers)
            {
                handler.Handle(domainEvent);
            }
        }
Exemple #6
0
        public IEnumerable <DomainEventHandler> GetWrappedHandlers(BaseDomainEvent domainEvent)
        {
            if (domainEvent == null)
            {
                throw new ArgumentNullException(nameof(domainEvent));
            }

            Type handlerType = typeof(IHandle <>).MakeGenericType(domainEvent.GetType());
            Type wrapperType = typeof(DomainEventHandler <>).MakeGenericType(domainEvent.GetType());
            IEnumerable <object>             handlers        = _serviceProvider.GetServices(handlerType);
            IEnumerable <DomainEventHandler> wrappedHandlers = handlers
                                                               .Select(handler => (DomainEventHandler)Activator.CreateInstance(wrapperType, handler));

            return(wrappedHandlers);
        }
        public async Task Dispatch(BaseDomainEvent domainEvent)
        {
            var handlerType = typeof(IDomainEventHandler <>).MakeGenericType(domainEvent.GetType());
            var wrapperType = typeof(DomainEventHandler <>).MakeGenericType(domainEvent.GetType());
            IEnumerable <object> handlers = _container.GetAllInstances(handlerType);



            var wrappedHandlers = handlers
                                  .Select(handler => (DomainEventHandler)Activator.CreateInstance(wrapperType, handler));

            foreach (var handler in wrappedHandlers)
            {
                await handler.Handle(domainEvent);
            }
        }
Exemple #8
0
        private IEnumerable <T?> GetWrappedHandlers <T>(BaseDomainEvent domainEvent, Type handlerType, Type wrappedHandlerType)
        {
            var genericHandlerType = handlerType.MakeGenericType(domainEvent.GetType());
            var handlers           = (IEnumerable?)_services.GetService(typeof(IEnumerable <>).MakeGenericType(genericHandlerType));

            if (handlers != null)
            {
                var wrapperType     = wrappedHandlerType.MakeGenericType(domainEvent.GetType());
                var wrappedHandlers = handlers
                                      .Cast <object>()
                                      .Select(handler => (T?)Activator.CreateInstance(wrapperType, handler));

                return(wrappedHandlers);
            }

            return(new List <T>());
        }
Exemple #9
0
        public void Dispatch(BaseDomainEvent domainEvent)
        {
            // Get handler type of the domain event
            var handlerType = typeof(IHandler <>).MakeGenericType(domainEvent.GetType());

            // Get Domain Event Handler of the domain event
            var domainEventHandlerType = typeof(DomainEventHandler <>).MakeGenericType(domainEvent.GetType());

            // Get all handlers of the handler type from IoC container
            var handlers = _container.GetAllInstances(handlerType);

            var domainEventHandlers = handlers
                                      .Cast <object>()
                                      .Select(handler => (DomainEventHandler)Activator.CreateInstance(domainEventHandlerType, handler));

            foreach (var handler in domainEventHandlers)
            {
                handler.Handle(domainEvent);
            }
        }