public void RemoveSubscription(Type eventType, Type handlerType) { var baseHandlerType = typeof(IIntegrationEventHandler <>).MakeGenericType(eventType); if (!baseHandlerType.IsAssignableFrom(handlerType)) { return; } var eventName = EventNameAttribute.GetNameOrDefault(eventType); var handlerToRemove = TryFindSubscriptionToRemove(eventName, baseHandlerType); TryRemoveHandler(eventName, handlerToRemove); }
private void TryAddSubscriptionEventHandler(Type eventType, Type baseHandlerType) { var eventName = EventNameAttribute.GetNameOrDefault(eventType); if (!IncludeSubscriptionsHandlesForEventName(eventName)) { _handlers.GetOrAdd(eventName, new List <Type>()); } if (_handlers[eventName].Any(s => s == baseHandlerType)) { throw new ArgumentException( $"Handler Type {baseHandlerType.Name} already registered for '{eventName}'", nameof(baseHandlerType)); } _handlers[eventName].Add(baseHandlerType); }
private void TryAddSubscriptionEventType(Type eventType) { var eventName = EventNameAttribute.GetNameOrDefault(eventType); if (_eventTypes.ContainsKey(eventName)) { //duplicate event key if (_eventTypes[eventName] != eventType) { throw new ArgumentException( $"Event name {eventName} already exists,please make sure the event key is unique"); } } else { _eventTypes[eventName] = eventType; } }