/// <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>
        ///     Adds the <see cref="IIntegrationSpy" /> and its support services to the
        ///     <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="attachSubscriber">
        ///     Specifies whether a generic subscriber (<see cref="InboundSpySubscriber" /> must be used to monitor the
        ///     inbound messages instead of a behavior (<see cref="InboundSpyBrokerBehavior" />).
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddIntegrationSpy(
            this ISilverbackBuilder silverbackBuilder,
            bool attachSubscriber = false)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder
            .AddSingletonBrokerBehavior <OutboundSpyBrokerBehavior>()
            .AddSingletonBrokerBehavior <RawOutboundSpyBrokerBehavior>()
            .AddSingletonBrokerBehavior <RawInboundSpyBrokerBehavior>();

            if (attachSubscriber)
            {
                silverbackBuilder.AddSingletonSubscriber <InboundSpySubscriber>();
            }
            else
            {
                silverbackBuilder.AddSingletonBrokerBehavior <InboundSpyBrokerBehavior>();
            }

            silverbackBuilder.Services
            .AddSingleton <IIntegrationSpy>(
                serviceProvider => serviceProvider.GetRequiredService <IntegrationSpy>())
            .AddSingleton <IntegrationSpy>();

            return(silverbackBuilder);
        }
Example #3
0
        /// <summary>
        ///     Adds the <see cref="IDistributedLockManager" /> implementation and uses the specified DbContext to
        ///     handle the distributed locks.
        /// </summary>
        /// <param name="builder">
        ///     The <see cref="ISilverbackBuilder" /> to add the model types to.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddDbDistributedLockManager(this ISilverbackBuilder builder)
        {
            Check.NotNull(builder, nameof(builder));

            builder.Services.AddSingleton <IDistributedLockManager, DbDistributedLockManager>();

            return(builder);
        }
        /// <summary>
        /// Registers the fake in-memory message broker.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="optionsAction">Additional options (such as connectors).</param>
        /// <returns></returns>
        public static ISilverbackBuilder WithInMemoryBroker(
            this ISilverbackBuilder builder,
            Action <BrokerOptionsBuilder> optionsAction = null)
        {
            builder.WithConnectionTo <InMemoryBroker>(optionsAction);

            return(builder);
        }
        /// <summary>
        ///     Adds a scoped behavior of the type specified in <paramref name="behaviorType" /> to the
        ///     <see cref="IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the behavior to.
        /// </param>
        /// <param name="behaviorType">
        ///     The type of the behavior to register and the implementation to use.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddScopedBehavior(this ISilverbackBuilder silverbackBuilder, Type behaviorType)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));
            Check.NotNull(behaviorType, nameof(behaviorType));

            silverbackBuilder.Services.AddScoped(typeof(IBehavior), behaviorType);
            return(silverbackBuilder);
        }
        public static ISilverbackBuilder UseOpenTracing(this ISilverbackBuilder builder)
        {
            builder.Services
            .AddSingletonBrokerBehavior <ConsumerTracingBehavior>()
            .AddSingletonBrokerBehavior <ProducerTracingBehavior>();

            return(builder);
        }
Example #7
0
        /// <summary>
        ///     Adds a scoped outbound router of the type specified in <paramref name="routerType" /> to the
        ///     <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="routerType">
        ///     The type of the outbound router to register and the implementation to use.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddScopedOutboundRouter(
            this ISilverbackBuilder silverbackBuilder,
            Type routerType)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddScoped(routerType);

            return(silverbackBuilder);
        }
Example #8
0
        /// <summary>
        ///     Adds a transient outbound router with a factory specified in
        ///     <paramref name="implementationFactory" /> to the
        ///     <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="implementationFactory">
        ///     The factory that creates the service.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddTransientOutboundRouter(
            this ISilverbackBuilder silverbackBuilder,
            Func <IServiceProvider, IOutboundRouter> implementationFactory)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddTransient(implementationFactory);

            return(silverbackBuilder);
        }
        /// <summary>
        /// Registers the specified DbContext to be used as underlying storage for the
        /// services requiring it.
        /// </summary>
        /// <typeparam name="TDbContext">The type of the <see cref="DbContext"/> to be used.</typeparam>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static ISilverbackBuilder UseDbContext <TDbContext>(this ISilverbackBuilder builder)
            where TDbContext : DbContext
        {
            SilverbackQueryableExtensions.Implementation = new EfCoreQueryableExtensions();

            builder.Services
            .AddScoped <IDbContext>(s => new EfCoreDbContext <TDbContext>(s.GetRequiredService <TDbContext>()));

            return(builder);
        }
Example #10
0
        /// <summary>
        ///     Adds a transient behavior with a factory specified in <paramref name="implementationFactory" /> to
        ///     the <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="implementationFactory">
        ///     The factory that creates the service.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddTransientBrokerBehavior(
            this ISilverbackBuilder silverbackBuilder,
            Func <IServiceProvider, IBrokerBehavior> implementationFactory)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddTransient(typeof(IBrokerBehavior), implementationFactory);

            return(silverbackBuilder);
        }
Example #11
0
        /// <summary>
        /// Registers the default messages model from Silverback.Core.Model package
        /// and the specific publishers (<see cref="ICommandPublisher"/>, <see cref="IQueryPublisher"/>,
        /// <see cref="IEventPublisher"/> and <see cref="IRequestPublisher"/>).
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static ISilverbackBuilder UseModel(this ISilverbackBuilder builder)
        {
            builder.Services
            .AddScoped <ICommandPublisher, CommandPublisher>()
            .AddScoped <IQueryPublisher, QueryPublisher>()
            .AddScoped <IEventPublisher, EventPublisher>()
            .AddScoped <IRequestPublisher, RequestPublisher>();

            return(builder);
        }
        /// <summary>
        ///     Adds a singleton behavior with a factory specified in <paramref name="implementationFactory" /> to
        ///     the <see cref="IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the behavior to.
        /// </param>
        /// <param name="implementationFactory">
        ///     The factory that creates the service.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddSingletonBehavior(
            this ISilverbackBuilder silverbackBuilder,
            Func <IServiceProvider, IBehavior> implementationFactory)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));
            Check.NotNull(implementationFactory, nameof(implementationFactory));

            silverbackBuilder.Services.AddSingleton(typeof(IBehavior), implementationFactory);
            return(silverbackBuilder);
        }
Example #13
0
        /// <summary>
        /// Registers Apache Kafka as message broker.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="optionsAction">Additional options (such as connectors).</param>
        /// <returns></returns>
        public static ISilverbackBuilder WithConnectionToKafka(
            this ISilverbackBuilder builder,
            Action <BrokerOptionsBuilder> optionsAction = null)
        {
            builder.WithConnectionTo <KafkaBroker>(optionsAction);

            builder.AddSingletonBehavior <KafkaPartitioningKeyBehavior>();

            return(builder);
        }
        /// <summary>
        ///     Adds an <see cref="IEndpointsConfigurator" /> to be used to setup the broker endpoints.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="implementationFactory">
        ///     The factory that creates the <see cref="IEndpointsConfigurator" /> to add.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddEndpointsConfigurator(
            this ISilverbackBuilder silverbackBuilder,
            Func <IServiceProvider, IEndpointsConfigurator> implementationFactory)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddScoped(implementationFactory);

            return(silverbackBuilder);
        }
        /// <summary>
        ///     Adds an <see cref="IEndpointsConfigurator" /> to be used to setup the broker endpoints.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="configuratorType">
        ///     The type of the <see cref="IEndpointsConfigurator" /> to add.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddEndpointsConfigurator(
            this ISilverbackBuilder silverbackBuilder,
            Type configuratorType)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddScoped(typeof(IEndpointsConfigurator), configuratorType);

            return(silverbackBuilder);
        }
Example #16
0
        /// <summary>
        ///     Adds a singleton behavior with an instance specified in <paramref name="implementationInstance" />
        ///     to the <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="implementationInstance">
        ///     The instance of the service.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddSingletonBrokerBehavior(
            this ISilverbackBuilder silverbackBuilder,
            IBrokerBehavior implementationInstance)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddSingleton(typeof(IBrokerBehavior), implementationInstance);

            return(silverbackBuilder);
        }
 /// <summary>
 ///     Registers the base type to be resolved as subscriber. The actual types have to be added to the
 ///     <see cref="IServiceCollection" /> separately.
 /// </summary>
 /// <typeparam name="TSubscriber">
 ///     The base type of the subscribers (class or interface).
 /// </typeparam>
 /// <param name="silverbackBuilder">
 ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
 ///     the subscriber to.
 /// </param>
 /// <param name="autoSubscribeAllPublicMethods">
 ///     A boolean value indicating whether all public methods of the specified type have to be automatically
 ///     subscribed. When set to <c>false</c> only the methods decorated with the
 ///     <see cref="SubscribeAttribute" /> are subscribed.
 /// </param>
 /// <returns>
 ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
 /// </returns>
 /// <remarks>
 ///     The subscribers will have to be registered twice (with the base type and the type itself:
 ///     <c>.AddScoped&lt;BaseType, Subscriber&gt;.AddScoped&lt;Subscriber&gt;</c>).
 /// </remarks>
 public static ISilverbackBuilder AddSubscribers <TSubscriber>(
     this ISilverbackBuilder silverbackBuilder,
     bool autoSubscribeAllPublicMethods = true)
     where TSubscriber : class =>
 AddSubscribers <TSubscriber>(
     silverbackBuilder,
     new TypeSubscriptionOptions
 {
     AutoSubscribeAllPublicMethods = autoSubscribeAllPublicMethods
 });
Example #18
0
        /// <summary>
        ///     Adds a singleton behavior of the type specified in <paramref name="behaviorType" /> to the
        ///     <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="behaviorType">
        ///     The type of the behavior to register and the implementation to use.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddSingletonBrokerBehavior(
            this ISilverbackBuilder silverbackBuilder,
            Type behaviorType)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddSingleton(typeof(IBrokerBehavior), behaviorType);

            return(silverbackBuilder);
        }
Example #19
0
        /// <summary>
        ///     Adds a singleton outbound router with an instance specified in
        ///     <paramref name="implementationInstance" /> to the
        ///     <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="implementationInstance">
        ///     The instance of the service.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddSingletonOutboundRouter(
            this ISilverbackBuilder silverbackBuilder,
            IOutboundRouter implementationInstance)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddSingleton(implementationInstance);

            return(silverbackBuilder);
        }
        /// <summary>
        ///     Adds a transient sequence reader of the type specified in <paramref name="readerType" /> to the
        ///     <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="readerType">
        ///     The type of the reader to register and the implementation to use.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddTransientSequenceReader(
            this ISilverbackBuilder silverbackBuilder,
            Type readerType)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddTransient(typeof(ISequenceReader), readerType);

            return(silverbackBuilder);
        }
        /// <summary>
        ///     Adds a singleton sequence writer of the type specified in <paramref name="writerType" /> to the
        ///     <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="writerType">
        ///     The type of the writer to register and the implementation to use.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddSingletonSequenceWriter(
            this ISilverbackBuilder silverbackBuilder,
            Type writerType)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddSingleton(typeof(ISequenceWriter), writerType);

            return(silverbackBuilder);
        }
        /// <summary>
        ///     Adds an <see cref="IEndpointsConfigurator" /> to be used to setup the broker endpoints.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <typeparam name="TConfigurator">
        ///     The type of the <see cref="IEndpointsConfigurator" /> to add.
        /// </typeparam>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddEndpointsConfigurator <TConfigurator>(
            this ISilverbackBuilder silverbackBuilder)
            where TConfigurator : class, IEndpointsConfigurator
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddScoped <IEndpointsConfigurator, TConfigurator>();

            return(silverbackBuilder);
        }
        /// <summary>
        ///     Adds a singleton sequence writer with an instance specified in
        ///     <paramref name="implementationInstance" />
        ///     to the <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="implementationInstance">
        ///     The instance of the service.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddSingletonSequenceWriter(
            this ISilverbackBuilder silverbackBuilder,
            ISequenceWriter implementationInstance)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddSingleton(typeof(ISequenceWriter), implementationInstance);

            return(silverbackBuilder);
        }
        /// <summary>
        ///     Adds a transient sequence writer with a factory specified in <paramref name="implementationFactory" />
        ///     to
        ///     the <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="implementationFactory">
        ///     The factory that creates the service.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddTransientSequenceWriter(
            this ISilverbackBuilder silverbackBuilder,
            Func <IServiceProvider, ISequenceWriter> implementationFactory)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services.AddTransient(typeof(ISequenceWriter), implementationFactory);

            return(silverbackBuilder);
        }
Example #25
0
        /// <summary>
        ///     Allows the subscribers to receive an <see cref="IObservable{T}" /> or an
        ///     <see cref="IMessageStreamObservable{TMessage}" /> as parameter.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AsObservable(this ISilverbackBuilder silverbackBuilder)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));

            silverbackBuilder.Services
            .AddSingleton <IArgumentResolver, ObservableStreamMessageArgumentResolver>()
            .AddScoped <IReturnValueHandler, ObservableMessagesReturnValueHandler>();

            return(silverbackBuilder);
        }
Example #26
0
        /// <summary>
        ///     Adds a transient callback with a factory specified in <paramref name="implementationFactory" /> to
        ///     the
        ///     <see cref="IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the handler to.
        /// </param>
        /// <param name="implementationFactory">
        ///     The factory that creates the service.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddTransientBrokerCallbackHandler(
            this ISilverbackBuilder silverbackBuilder,
            Func <IServiceProvider, IBrokerCallback> implementationFactory)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));
            Check.NotNull(implementationFactory, nameof(implementationFactory));

            silverbackBuilder.Services.AddTransient(typeof(IBrokerCallback), implementationFactory);
            return(silverbackBuilder);
        }
Example #27
0
        /// <summary>
        ///     Adds a transient callback of the type specified in <paramref name="handlerType" /> to the
        ///     <see cref="IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the handler to.
        /// </param>
        /// <param name="handlerType">
        ///     The type of the handler to register and the implementation to use.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddTransientBrokerCallbackHandler(
            this ISilverbackBuilder silverbackBuilder,
            Type handlerType)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));
            Check.NotNull(handlerType, nameof(handlerType));

            silverbackBuilder.Services.AddTransient(typeof(IBrokerCallback), handlerType);
            return(silverbackBuilder);
        }
Example #28
0
        /// <summary>
        ///     Adds a singleton callback with an instance specified in <paramref name="implementationInstance" />
        ///     to the <see cref="IServiceCollection" />.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the handler to.
        /// </param>
        /// <param name="implementationInstance">
        ///     The instance of the service.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddSingletonBrokerCallbackHandler(
            this ISilverbackBuilder silverbackBuilder,
            IBrokerCallback implementationInstance)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));
            Check.NotNull(implementationInstance, nameof(implementationInstance));

            silverbackBuilder.Services.AddSingleton(typeof(IBrokerCallback), implementationInstance);
            return(silverbackBuilder);
        }
Example #29
0
        /// <summary>
        ///     Adds the broker endpoints.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IServiceCollection" /> to add
        ///     the services to.
        /// </param>
        /// <param name="configureAction">
        ///     An <see cref="Action{T}" /> that takes the <see cref="IEndpointsConfigurationBuilder" /> and adds the
        ///     outbound and inbound endpoints.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddEndpoints(
            this ISilverbackBuilder silverbackBuilder,
            Action <IEndpointsConfigurationBuilder> configureAction)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));
            Check.NotNull(configureAction, nameof(configureAction));

            silverbackBuilder.AddEndpointsConfigurator(_ => new GenericEndpointsConfigurator(configureAction));

            return(silverbackBuilder);
        }
Example #30
0
        /// <summary>
        ///     Subscribes the specified delegate to the messages being published into the bus.
        /// </summary>
        /// <param name="silverbackBuilder">
        ///     The <see cref="ISilverbackBuilder" /> that references the <see cref="IBusOptions" /> to be configured.
        /// </param>
        /// <typeparam name="TMessage">
        ///     The type of the messages to be handled.
        /// </typeparam>
        /// <param name="handler">
        ///     The message handler delegate.
        /// </param>
        /// <param name="options">
        ///     A <see cref="SubscriptionOptions" /> specifying parallelism options.
        /// </param>
        /// <returns>
        ///     The <see cref="ISilverbackBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static ISilverbackBuilder AddDelegateSubscriber <TMessage>(
            this ISilverbackBuilder silverbackBuilder,
            Func <TMessage, Task> handler,
            SubscriptionOptions?options = null)
        {
            Check.NotNull(silverbackBuilder, nameof(silverbackBuilder));
            Check.NotNull(handler, nameof(handler));

            silverbackBuilder.BusOptions.Subscriptions.Add(new DelegateSubscription(handler, options));
            return(silverbackBuilder);
        }