Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageRouter"/> class.
        /// </summary>
        /// <param name="serviceProvider">The service provider instance to retrieve all the <see cref="IMessageHandler{TMessage,TMessageContext}"/> instances.</param>
        /// <param name="options">The consumer-configurable options to change the behavior of the router.</param>
        /// <param name="logger">The logger instance to write diagnostic trace messages during the routing of the message.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="serviceProvider"/> is <c>null</c>.</exception>
        protected MessageRouter(IServiceProvider serviceProvider, MessageRouterOptions options, ILogger logger)
        {
            Guard.NotNull(serviceProvider, nameof(serviceProvider), "Requires a service provider instance to retrieve all the registered message handlers");

            ServiceProvider = serviceProvider;
            Options         = options ?? new MessageRouterOptions();
            Logger          = logger ?? NullLogger <MessageRouter> .Instance;

            _fallbackMessageHandler = new Lazy <IFallbackMessageHandler>(() => serviceProvider.GetService <IFallbackMessageHandler>());
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageRouter"/> class.
 /// </summary>
 /// <param name="serviceProvider">The service provider instance to retrieve all the <see cref="IMessageHandler{TMessage,TMessageContext}"/> instances.</param>
 /// <param name="options">The consumer-configurable options to change the behavior of the router.</param>
 /// <exception cref="ArgumentNullException">Thrown when the <paramref name="serviceProvider"/> is <c>null</c>.</exception>
 public MessageRouter(IServiceProvider serviceProvider, MessageRouterOptions options)
     : this(serviceProvider, options, NullLogger.Instance)
 {
     Guard.NotNull(serviceProvider, nameof(serviceProvider), "Requires a service provider instance to retrieve all the registered message handlers");
 }