/// <summary> /// Metadata of the message subscription /// </summary> public MessageSubscription( MessageSubscriptionOptions <TMessage> options, IReadOnlyCollection <IMessageFilter> globalFilters) { _options = options ?? throw new ArgumentNullException(nameof(options)); _globalFilters = globalFilters ?? throw new ArgumentNullException(nameof(globalFilters)); }
/// <inheritdoc /> public MessageSubscriptionsRegistry Handle <TMessage, TState>(Action <IMessageSubscriptionOptions <TMessage, TState> > configureSubscription) where TMessage : class { if (configureSubscription == null) { throw new ArgumentNullException(nameof(configureSubscription)); } var messageType = typeof(TMessage); var subscriptionOptions = new MessageSubscriptionOptions <TMessage, TState>(messageType.Name); configureSubscription.Invoke(subscriptionOptions); if (subscriptionOptions.HandlerType == null) { throw new InvalidOperationException($"Handler is not registered for the message {messageType.Name}."); } _subscriptions = _subscriptions.Add(messageType.Name, new MessageSubscription <TMessage, TState>(subscriptionOptions, _globalFilters)); return(this); }