Example #1
0
        public CommandProcessorConfigurationBuilder(IServiceCollection services)
        {
            _services     = services;
            _newContainer = new NewConfigurationContainer(services);

            FillInDefaults();
        }
        /// <summary>
        /// Registers a <see cref="Views.ViewManagerEventDispatcher"/> to manage the given views. Can be called multiple times in order to register
        /// multiple "pools" of views (each will be managed by a dedicated worker thread).
        /// </summary>
        public ViewManagerEventDispatcherConfigurationBuilder UseViewManagerEventDispatcher(params IViewManager[] viewManagers)
        {
            var viewManagerConfigurationContainer = new NewConfigurationContainer(_services);

            UseEventDispatcher(context =>
            {
                var scope = context.CreateScope();

                var eventDispatcher = new ViewManagerEventDispatcher(
                    scope.ServiceProvider.GetService <IAggregateRootRepository>(),
                    scope.ServiceProvider.GetService <IEventStore>(),
                    scope.ServiceProvider.GetService <IDomainEventSerializer>(),
                    scope.ServiceProvider.GetService <IDomainTypeNameMapper>(),
                    viewManagers);

                var waitHandle = scope.ServiceProvider.GetService <ViewManagerWaitHandle>();
                if (waitHandle != null)
                {
                    waitHandle.Register(eventDispatcher);
                }

                var configuration = scope.ServiceProvider.GetService <ViewManagerEventDispatcherConfiguration>();
                if (configuration?.MaxDomainEventsPerBatch > 0)
                {
                    eventDispatcher.MaxDomainEventsPerBatch = configuration.MaxDomainEventsPerBatch;
                }

                var viewManagerProfiler = scope.ServiceProvider.GetService <IViewManagerProfiler>();
                if (viewManagerProfiler != null)
                {
                    eventDispatcher.SetProfiler(viewManagerProfiler);
                }

                var contextItems = scope.ServiceProvider.GetService <IDictionary <string, object> >();
                if (contextItems != null)
                {
                    eventDispatcher.SetContextItems(contextItems);
                }

                var autoDistributionViewManagerEventDispatcher = scope.ServiceProvider.GetService <AutoDistributionViewManagerEventDispatcher>();
                if (autoDistributionViewManagerEventDispatcher != null)
                {
                    autoDistributionViewManagerEventDispatcher.Register(eventDispatcher);
                    return(autoDistributionViewManagerEventDispatcher);
                }

                return(eventDispatcher);
            });

            return(new ViewManagerEventDispatcherConfigurationBuilder(viewManagerConfigurationContainer));
        }