コード例 #1
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 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}");
        }
コード例 #2
0
        /// <summary>
        /// Adds a configuration object to the collection.
        /// </summary>
        /// <typeparam name="TDomainModelRoot">The domain model to which this configuration applies.</typeparam>
        /// <param name="config">The library configuration.</param>
        public void AddConfiguration <TDomainModelRoot>(EventStreamDotNetConfig config)
            where TDomainModelRoot : class, IDomainModelRoot, new()
        {
            if (string.IsNullOrWhiteSpace(config.Database.ConnectionString) ||
                string.IsNullOrWhiteSpace(config.Database.EventTableName) ||
                string.IsNullOrWhiteSpace(config.Database.SnapshotTableName))
            {
                throw new ArgumentException("Missing one or more required database configuration values");
            }

            var domainType = typeof(TDomainModelRoot);

            if (cache.ContainsKey(domainType))
            {
                return;
            }
            cache.Add(domainType, config);

            logger.LogDebug($"Registering configuration for domain model {domainType.Name}");
        }