/// <summary> /// Execute the request via the worker. /// </summary> /// <param name="request">The <see cref="EventHandlerRequest"/> to execute.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> to cancel the execution.</param> /// <returns>The <see cref="Task"/> of the event.</returns> public async Task PublishAsync(EventHandlerRequest request, CancellationToken cancellationToken) { if (request == null) { throw Error.ArgumentNull("request"); } IEventHandlerSelector handlerSelector = this.Configuration.Services.GetEventHandlerSelector(); EventHandlersDescriptor eventDescriptor = handlerSelector.SelectHandlers(request); var descriptors = eventDescriptor.EventHandlerDescriptors; for (int i = 0; i < descriptors.Count; i++) { await InvokeHandlerAsync(descriptors[i], request, cancellationToken); } }
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; }
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); }