/// <summary>
        /// Prepares the EventStreamDotNet library services for dependency injection.
        /// </summary>
        /// <param name="services">The DI service collection.</param>
        /// <param name="LoggerFactory">When set, the library will emit Debug-level log output to the configured logger.</param>
        /// <param name="domainModelConfigs">A lambda for registering domain model configurations.</param>
        /// <param name="domainEventHandlers">A lambda for registering domain event handlers.</param>
        /// <param name="projectionHandlers">A lambda for registering projection handlers.</param>
        public static IServiceCollection AddEventStreamDotNet(this IServiceCollection services,
                                                              ILoggerFactory loggerFactory = null,
                                                              Action <EventStreamConfigService> domainModelConfigs   = null,
                                                              Action <DomainEventHandlerService> domainEventHandlers = null,
                                                              Action <ProjectionHandlerService> projectionHandlers   = null)
        {
            if (loggerFactory != null)
            {
                loggerFactory.CreateLogger("EventStreamDotNet").LogDebug($"{nameof(AddEventStreamDotNet)} is configuring and registering library services");
            }

            // Create the services
            var svcConfigs = new EventStreamConfigService(loggerFactory);
            var svcEvents  = new DomainEventHandlerService(svcConfigs);
            var svcProjs   = new ProjectionHandlerService(svcConfigs);

            // Invoke the lambdas
            domainModelConfigs?.Invoke(svcConfigs);
            domainEventHandlers?.Invoke(svcEvents);
            projectionHandlers?.Invoke(svcProjs);

            // Register the services for injection
            services.AddSingleton(svcConfigs);
            services.AddSingleton(svcEvents);
            services.AddSingleton(svcProjs);

            return(services);
        }
        /// <summary>
        /// Constructor with optional lambda-style configuration.
        /// </summary>
        /// <param name="LoggerFactory">When set, the library will emit Debug-level log output to the configured logger.</param>
        public DirectDependencyServiceHost(
            ILoggerFactory loggerFactory = null,
            Action <EventStreamConfigService> domainModelConfigs   = null,
            Action <DomainEventHandlerService> domainEventHandlers = null,
            Action <ProjectionHandlerService> projectionHandlers   = null)
        {
            // Create the services
            EventStreamConfigs  = new EventStreamConfigService(loggerFactory);
            DomainEventHandlers = new DomainEventHandlerService(EventStreamConfigs);
            ProjectionHandlers  = new ProjectionHandlerService(EventStreamConfigs);

            // Invoke the lambdas
            domainModelConfigs?.Invoke(EventStreamConfigs);
            domainEventHandlers?.Invoke(DomainEventHandlers);
            projectionHandlers?.Invoke(ProjectionHandlers);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="configService">A collection of library configuration settings.</param>
        /// <param name="eventHandlerService">A collection of domain event handlers.</param>
        /// <param name="projectionHandlerService">A collection of domain model projection handlers.</param>
        public EventStreamProcessor(EventStreamConfigService configService, DomainEventHandlerService eventHandlerService, ProjectionHandlerService projectionHandlerService)
        {
            if (!configService.ContainsConfiguration <TDomainModelRoot>())
            {
                throw new Exception($"No configuration registered for domain model {typeof(TDomainModelRoot).Name}");
            }

            this.eventHandlerService      = eventHandlerService;
            this.projectionHandlerService = projectionHandlerService;

            IsInitialized = false;
            config        = configService.GetConfiguration <TDomainModelRoot>();
            logger        = new DebugLogger <EventStreamProcessor <TDomainModelRoot> >(configService.LoggerFactory);

            logger.LogDebug($"Created {nameof(EventStreamProcessor<TDomainModelRoot>)} for domain model root {typeof(TDomainModelRoot).Name}");
        }
Example #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="configService">A collection of library configuration settings.</param>
        /// <param name="eventHandlerService">A collection of domain event handlers.</param>
        /// <param name="projectionHandlerService">A collection of domain model projection handlers.</param>
        public EventStreamManager(EventStreamConfigService configService, DomainEventHandlerService eventHandlerService, ProjectionHandlerService projectionHandlerService)
        {
            if (!configService.ContainsConfiguration <TDomainModelRoot>())
            {
                throw new Exception($"No configuration registered for domain model {typeof(TDomainModelRoot).Name}");
            }

            eventStream = new EventStreamProcessor <TDomainModelRoot>(configService, eventHandlerService, projectionHandlerService);
            logger      = new DebugLogger <EventStreamManager <TDomainModelRoot> >(configService.LoggerFactory);

            logger.LogDebug($"Created {nameof(EventStreamManager<TDomainModelRoot>)} for domain model root {typeof(TDomainModelRoot).Name}");
        }