/// <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); }
public static IServiceCollection AddBroker <T>(this IServiceCollection services, Action <BrokerOptionsBuilder> optionsAction = null) where T : class, IBroker { services .AddSingleton <IBroker, T>() .AddSingleton <ErrorPolicyBuilder>() .AddSingleton <IMessageKeyProvider, DefaultPropertiesMessageKeyProvider>() .AddSingleton <MessageKeyProvider>() .AddSingleton <MessageLogger>(); var options = new BrokerOptionsBuilder(services); optionsAction?.Invoke(options); options.CompleteWithDefaults(); return(services); }
/// <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); }
/// <summary> /// Registers the message broker of the specified type. /// </summary> /// <typeparam name="T">The type of the message broker implementation.</typeparam> /// <param name="builder"></param> /// <param name="optionsAction">Additional options (such as connectors).</param> /// <returns></returns> public static ISilverbackBuilder WithConnectionTo <T>(this ISilverbackBuilder builder, Action <BrokerOptionsBuilder> optionsAction = null) where T : class, IBroker { builder.Services .AddSingleton <IBroker, T>() .AddSingleton <ErrorPolicyBuilder>() .AddSingleton <MessageKeyProvider>() .AddSingleton <MessageLogger>() .AddSingletonBrokerBehavior <ActivityProducerBehavior>() .AddSingletonBrokerBehavior <ActivityConsumerBehavior>(); var options = new BrokerOptionsBuilder(builder); optionsAction?.Invoke(options); options.CompleteWithDefaults(); return(builder); }