/// <summary>
        /// Adds a connector to publish the integration messages to the configured message broker.
        /// </summary>
        public BrokerOptionsBuilder AddOutboundConnector <TConnector>() where TConnector : class, IOutboundConnector
        {
            if (SilverbackBuilder.Services.All(s => s.ServiceType != typeof(IOutboundRoutingConfiguration)))
            {
                SilverbackBuilder.Services.AddSingleton <IOutboundRoutingConfiguration, OutboundRoutingConfiguration>();
                SilverbackBuilder.AddScopedBehavior <OutboundProducingBehavior>();
                SilverbackBuilder.AddScopedBehavior <OutboundRoutingBehavior>();
            }

            SilverbackBuilder.Services.AddScoped <IOutboundConnector, TConnector>();

            return(this);
        }
        /// <summary>
        ///     Registers the types needed to connect with a message broker.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="optionsAction">
        ///     Additional options (such as message broker type and connectors).
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder WithConnectionToMessageBroker(
            this ISilverbackBuilder silverbackBuilder,
            Action <IBrokerOptionsBuilder>?optionsAction = null)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            // Outbound Routing
            silverbackBuilder
            .AddScopedBehavior <OutboundRouterBehavior>()
            .AddScopedBehavior <ProduceBehavior>()
            .Services
            .AddSingleton <IOutboundRoutingConfiguration, OutboundRoutingConfiguration>();

            // Broker Collection
            silverbackBuilder.Services
            .AddSingleton <IBrokerCollection, BrokerCollection>();

            // Logging
            silverbackBuilder.Services
            .AddSingleton <ILogTemplates>(new LogTemplates())
            .AddSingleton(typeof(ISilverbackIntegrationLogger <>), typeof(SilverbackIntegrationLogger <>));

            // Transactional Lists
            silverbackBuilder.Services
            .AddSingleton(typeof(TransactionalListSharedItems <>))
            .AddSingleton(typeof(TransactionalDictionarySharedItems <,>));

            var optionsBuilder = new BrokerOptionsBuilder(silverbackBuilder);

            optionsAction?.Invoke(optionsBuilder);
            optionsBuilder.CompleteWithDefaults();

            return(silverbackBuilder);
        }
        /// <summary>
        ///     Registers the types needed to connect with a message broker.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="optionsAction">
        ///     Additional options such as the actual message brokers to be used.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder WithConnectionToMessageBroker(
            this ISilverbackBuilder silverbackBuilder,
            Action <IBrokerOptionsBuilder>?optionsAction = null)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            // Outbound Routing
            silverbackBuilder
            .AddScopedBehavior <OutboundRouterBehavior>()
            .AddScopedBehavior <ProduceBehavior>()
            .Services
            .AddSingleton <OutboundEnvelopeFactory>()
            .AddSingleton <IOutboundRoutingConfiguration>(new OutboundRoutingConfiguration());

            // Broker Collection
            silverbackBuilder.Services
            .AddSingleton <IBrokerCollection, BrokerCollection>();

            // Logging
            silverbackBuilder.Services
            .AddSingleton(typeof(IInboundLogger <>), typeof(InboundLogger <>))
            .AddSingleton(typeof(IOutboundLogger <>), typeof(OutboundLogger <>))
            .AddSingleton <InboundLoggerFactory>()
            .AddSingleton <OutboundLoggerFactory>()
            .AddSingleton <BrokerLogEnricherFactory>()
            .AddSingleton <IBrokerOutboundMessageEnrichersFactory, BrokerOutboundMessageEnrichersFactory>();

            // Activities
            silverbackBuilder.Services.AddSingleton <IActivityEnricherFactory, ActivityEnricherFactory>();

            // Transactional Lists
            silverbackBuilder.Services
            .AddSingleton(typeof(TransactionalListSharedItems <>))
            .AddSingleton(typeof(TransactionalDictionarySharedItems <,>));

            // Event Handlers
            silverbackBuilder.Services.AddSingleton <IBrokerCallbacksInvoker, BrokerCallbackInvoker>();

            var optionsBuilder = new BrokerOptionsBuilder(silverbackBuilder);

            optionsAction?.Invoke(optionsBuilder);
            optionsBuilder.CompleteWithDefaults();

            return(silverbackBuilder);
        }