예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandHandlerContext"/> class. 
        /// </summary>
        /// <param name="request">The handler request.</param>
        /// <param name="descriptor">The handler descriptor.</param>
        public EventHandlerContext(EventHandlerRequest request, EventHandlerDescriptor descriptor)
            : this()
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            if (request.Configuration == null)
            {
                throw Error.Argument("request");
            }

            this.Configuration = request.Configuration;
            this.Request = request;
            this.Event = request.Event;
            this.Descriptor = descriptor;
            this.User = this.Configuration.Services.GetPrincipalProvider().Principal;
        }
예제 #2
0
        private static Task InvokeHandlerAsync(EventHandlerDescriptor descriptor, EventHandlerRequest request, CancellationToken cancellationToken)
        {
            Contract.Requires(descriptor != null);
            Contract.Requires(request != null);

            IEventHandler handler = descriptor.CreateHandler(request);
            if (handler == null)
            {
                throw CreateHandlerNotFoundException(descriptor);
            }

            request.RegisterForDispose(handler, true);
            EventHandlerContext context = new EventHandlerContext(request, descriptor);
            context.Handler = handler;
            handler.EventContext = context;
            EventFilterGrouping filterGrouping = descriptor.GetFilterGrouping();
     
            ServicesContainer servicesContainer = request.Configuration.Services;
            IEventHandlerResult result = new EventHandlerFilterResult(context, servicesContainer, filterGrouping.EventHandlerFilters);

            return result.ExecuteAsync(cancellationToken);
        }
예제 #3
0
        private ConcurrentDictionary<Type, EventHandlersDescriptor> InitializeHandlerInfoCache()
        {
            ConcurrentDictionary<Type, EventHandlersDescriptor> concurrentDictionary = new ConcurrentDictionary<Type, EventHandlersDescriptor>();
            Dictionary<Type, ILookup<Type, Type>> cache = this.handlerTypeCache.Cache;
            foreach (KeyValuePair<Type, ILookup<Type, Type>> current in cache)
            {
                Type eventType = current.Key;
                Collection<EventHandlerDescriptor> descriptors = new Collection<EventHandlerDescriptor>();
                foreach (IGrouping<Type, Type> group in current.Value)
                {
                    foreach (Type handlerType in group)
                    {
                        EventHandlerDescriptor descriptor = new EventHandlerDescriptor(this.configuration, eventType, handlerType);
                        descriptors.Add(descriptor);
                    }
                }

                EventHandlersDescriptor eventDescriptor = new EventHandlersDescriptor(eventType.Name, descriptors);
                concurrentDictionary.TryAdd(eventType, eventDescriptor);
            }
            
            return concurrentDictionary;
        }
예제 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 protected override void Action(IConventionalContext context)
 {
     context.Types.ForEach(
         t => context.Services.Configure <EventBusOptions>(options => options.Handlers.Add(EventHandlerDescriptor.Describe(t, context.Get <IEventHandlerActivationTypeSelector>("HandlerActivationTypeSelector").Select(t)))));
 }
예제 #5
0
        private static CommandHandlerNotFoundException CreateHandlerNotFoundException(EventHandlerDescriptor descriptor)
        {
            Contract.Requires(descriptor != null);

            return new CommandHandlerNotFoundException(descriptor.MessageType);
        }