Exemplo n.º 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 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}");
        }
        /// <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}");
        }
        /// <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}");
        }
 /// <summary>
 /// Constructor for non-DI-based client applications.
 /// </summary>
 /// <param name="LoggerFactory">When set, the library will emit Debug-level log output to the configured logger.</param>
 public EventStreamConfigService(ILoggerFactory loggerFactory = null)
 {
     LoggerFactory = loggerFactory;
     logger        = new DebugLogger <EventStreamConfigService>(loggerFactory);
     logger.LogDebug($"{nameof(EventStreamConfigService)} is starting");
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configService">A collection of library configuration settings.</param>
 public DomainEventHandlerService(EventStreamConfigService configService)
 {
     logger = new DebugLogger <DomainEventHandlerService>(configService.LoggerFactory);
     logger.LogDebug($"{nameof(DomainEventHandlerService)} is starting");
 }
        // ---------- Internal methods invoked by EventStreamManager

        /// <summary>
        /// Reads the snapshot and all newer events. See <see cref="ReadAllEvents"/> for details
        /// of how the snapshot may be updated.
        /// </summary>
        /// <param name="id">The unique identifier for this domain model object.</param>
        internal async Task Initialize(string id)
        {
            logger.LogDebug($"{nameof(Initialize)} ID {id}");

            if (!eventHandlerService.IsDomainEventHandlerRegistered <TDomainModelRoot>())
            {
                throw new Exception($"No domain event handler registered for domain model {typeof(TDomainModelRoot).Name}");
            }

            Id = id;

            IsInitialized = true;

            await ReadAllEvents();
        }
Exemplo n.º 7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="configService">A collection of library configuration settings.</param>
 public ProjectionHandlerService(EventStreamConfigService configService)
 {
     this.configService = configService;
     logger             = new DebugLogger <ProjectionHandlerService>(configService.LoggerFactory);
     logger.LogDebug($"{nameof(ProjectionHandlerService)} is starting");
 }