private static CommandProcessor BuildCommandProcessor(IServiceProvider provider)
        {
            var options            = provider.GetService <IBrighterOptions>();
            var subscriberRegistry = provider.GetService <ServiceCollectionSubscriberRegistry>();

            var handlerFactory       = new ServiceProviderHandlerFactory(provider);
            var handlerConfiguration = new HandlerConfiguration(subscriberRegistry, handlerFactory, handlerFactory);

            var messageMapperRegistry = MessageMapperRegistry(provider);

            var policyBuilder = CommandProcessorBuilder.With()
                                .Handlers(handlerConfiguration);

            var messagingBuilder = options.PolicyRegistry == null
                ? policyBuilder.DefaultPolicy()
                : policyBuilder.Policies(options.PolicyRegistry);

            var builder = options.BrighterMessaging == null
                ? messagingBuilder.NoTaskQueues()
                : messagingBuilder.TaskQueues(new MessagingConfiguration(options.BrighterMessaging.MessageStore, options.BrighterMessaging.Producer, messageMapperRegistry));

            var commandProcessor = builder
                                   .RequestContextFactory(options.RequestContextFactory)
                                   .Build();

            return(commandProcessor);
        }
Example #2
0
        private static CommandProcessor BuildCommandProcessor(IServiceProvider provider)
        {
            var options            = provider.GetService <IBrighterOptions>();
            var subscriberRegistry = provider.GetService <ServiceCollectionSubscriberRegistry>();

            var handlerFactory       = new ServiceProviderHandlerFactory(provider);
            var handlerConfiguration = new HandlerConfiguration(subscriberRegistry, handlerFactory, handlerFactory);

            var messageMapperRegistry = MessageMapperRegistry(provider);

            var policyBuilder = CommandProcessorBuilder.With()
                                .Handlers(handlerConfiguration);

            var messagingBuilder = options.PolicyRegistry == null
                ? policyBuilder.DefaultPolicy()
                : policyBuilder.Policies(options.PolicyRegistry);

            var loggerFactory = provider.GetService <ILoggerFactory>();

            ApplicationLogging.LoggerFactory = loggerFactory;

            INeedARequestContext taskQueuesBuilder;

            if (options.ChannelFactory is null)
            {
                //TODO: Need to add async outbox

                taskQueuesBuilder = options.BrighterMessaging == null
                    ? messagingBuilder.NoTaskQueues()
                    : messagingBuilder.TaskQueues(new MessagingConfiguration(options.BrighterMessaging.OutBox,
                                                                             options.BrighterMessaging.AsyncOutBox, options.BrighterMessaging.Producer,
                                                                             options.BrighterMessaging.AsyncProducer, messageMapperRegistry));
            }
            else
            {
                if (options.BrighterMessaging == null)
                {
                    taskQueuesBuilder = messagingBuilder.NoTaskQueues();
                }
                else
                {
                    taskQueuesBuilder = options.BrighterMessaging.UseRequestReplyQueues
                        ? messagingBuilder.RequestReplyQueues(new MessagingConfiguration(
                                                                  options.BrighterMessaging.OutBox,
                                                                  options.BrighterMessaging.Producer, messageMapperRegistry,
                                                                  responseChannelFactory: options.ChannelFactory))
                        : messagingBuilder.TaskQueues(new MessagingConfiguration(options.BrighterMessaging.OutBox,
                                                                                 options.BrighterMessaging.AsyncOutBox, options.BrighterMessaging.Producer,
                                                                                 options.BrighterMessaging.AsyncProducer, messageMapperRegistry));
                }
            }

            var commandProcessor = taskQueuesBuilder
                                   .RequestContextFactory(options.RequestContextFactory)
                                   .Build();

            return(commandProcessor);
        }
Example #3
0
        private static CommandProcessor BuildCommandProcessor(IServiceProvider provider)
        {
            var options            = provider.GetService <IBrighterOptions>();
            var subscriberRegistry = provider.GetService <ServiceCollectionSubscriberRegistry>();
            var useRequestResponse = provider.GetService <IUseRpc>();

            var handlerFactory       = new ServiceProviderHandlerFactory(provider);
            var handlerConfiguration = new HandlerConfiguration(subscriberRegistry, handlerFactory);

            var messageMapperRegistry = MessageMapperRegistry(provider);

            var outbox      = provider.GetService <IAmAnOutboxSync <Message> >();
            var asyncOutbox = provider.GetService <IAmAnOutboxAsync <Message> >();
            var overridingConnectionProvider = provider.GetService <IAmABoxTransactionConnectionProvider>();

            if (outbox == null)
            {
                outbox = new InMemoryOutbox();
            }
            if (asyncOutbox == null)
            {
                asyncOutbox = new InMemoryOutbox();
            }

            var inboxConfiguration = provider.GetService <InboxConfiguration>();

            var producerRegistry = provider.GetService <IAmAProducerRegistry>();

            var needHandlers = CommandProcessorBuilder.With();

            var featureSwitchRegistry = provider.GetService <IAmAFeatureSwitchRegistry>();

            if (featureSwitchRegistry != null)
            {
                needHandlers = needHandlers.ConfigureFeatureSwitches(featureSwitchRegistry);
            }

            var policyBuilder = needHandlers.Handlers(handlerConfiguration);

            var messagingBuilder = options.PolicyRegistry == null
                ? policyBuilder.DefaultPolicy()
                : policyBuilder.Policies(options.PolicyRegistry);

            var loggerFactory = provider.GetService <ILoggerFactory>();

            ApplicationLogging.LoggerFactory = loggerFactory;

            var commandProcessor = AddExternalBusMaybe(
                options,
                producerRegistry,
                messagingBuilder,
                messageMapperRegistry,
                inboxConfiguration,
                outbox,
                overridingConnectionProvider,
                useRequestResponse)
                                   .RequestContextFactory(options.RequestContextFactory)
                                   .Build();

            return(commandProcessor);
        }