private static IServiceCollection RegisterPatLite(
            this IServiceCollection serviceCollection,
            BatchPipelineDependencyBuilder batchMessageProcessingBehaviourBuilder,
            MessagePipelineDependencyBuilder messagePipelineDependencyBuilder,
            Func <IServiceProvider, IMessageDeserialiser> messageDeserialiser,
            Func <IServiceProvider, CircuitBreakerBatchProcessingBehaviour.CircuitBreakerOptions> circuitBreakerOptions)
        {
            messagePipelineDependencyBuilder?.RegisterTypes(serviceCollection);
            batchMessageProcessingBehaviourBuilder?.RegisterTypes(serviceCollection);

            var deserialisationResolver = messageDeserialiser ?? (provider => new NewtonsoftMessageDeserialiser());

            if (circuitBreakerOptions != null)
            {
                serviceCollection.AddSingleton(circuitBreakerOptions);
            }

            serviceCollection.AddTransient <IMessageDependencyResolver, MessageDependencyResolver>()
            .AddTransient <IMessageProcessor, MessageProcessor>()
            .AddScoped <DefaultMessageProcessingBehaviour>()
            .AddScoped <InvokeHandlerBehaviour>()
            .AddScoped <MonitoringMessageProcessingBehaviour>()
            .AddScoped <MonitoringBatchProcessingBehaviour>()
            .AddScoped <DefaultBatchProcessingBehaviour>()
            .AddSingleton <IMultipleBatchProcessor>(provider =>
                                                    new MultipleBatchProcessor(
                                                        provider.GetService <BatchProcessor>(),
                                                        provider.GetService <ILogger <MultipleBatchProcessor> >(),
                                                        provider.GetService <SubscriberConfiguration>().SubscriberName))
            .AddSingleton <IMessageReceiverFactory, AzureServiceBusMessageReceiverFactory>()
            .AddTransient <ISubscriptionBuilder, SubscriptionBuilder>()
            .AddSingleton <BatchFactory>()
            .AddSingleton <BatchProcessor>()
            .AddSingleton(provider => new BatchConfiguration(
                              provider.GetService <SubscriberConfiguration>().BatchSize,
                              provider.GetService <SubscriberConfiguration>().ReceiveTimeoutSeconds))
            .AddScoped(provider => provider.GetService <IMessageDependencyResolver>().BeginScope())
            .AddScoped(provider => new MessageContext())
            .AddSingleton(provider => batchMessageProcessingBehaviourBuilder != null ? batchMessageProcessingBehaviourBuilder.Build(provider) :
                          new BatchProcessingBehaviourPipeline()
                          .AddBehaviour <MonitoringBatchProcessingBehaviour>(provider)
                          .AddBehaviour <DefaultBatchProcessingBehaviour>(provider))
            .AddSingleton(provider => messagePipelineDependencyBuilder != null ? messagePipelineDependencyBuilder.Build(provider) :
                          new MessageProcessingBehaviourPipeline()
                          .AddBehaviour <DefaultMessageProcessingBehaviour>(provider)
                          .AddBehaviour <MonitoringMessageProcessingBehaviour>(provider)
                          .AddBehaviour <InvokeHandlerBehaviour>(provider))
            .AddScoped(deserialisationResolver)
            .AddSingleton <Subscriber>();

            return(serviceCollection);
        }
示例#2
0
        public PatLiteOptions Build()
        {
            EnsureTerminatingBehavioursAdded();

            var builder        = new MessagePipelineDependencyBuilder(_messagePipelineBehaviourTypes);
            var batchBuilder   = new BatchPipelineDependencyBuilder(_batchPipelineBehaviourTypes);
            var patliteOptions = new PatLiteOptions
            {
                SubscriberConfiguration          = _subscriberConfiguration,
                MessageProcessingPipelineBuilder = builder,
                BatchMessageProcessingBehaviourPipelineBuilder = batchBuilder,
                MessageDeserialiser   = _messageDeserialiser,
                CircuitBreakerOptions = _circuitBreakerOptions
            };

            return(patliteOptions);
        }