/// <summary> /// Create a new instance of <see cref="DefaultServicebus"/>. /// </summary> public DefaultServicebus(ILogger <DefaultServicebus> logger, IOptionsMonitor <ServicebusConfiguration> config, IDomainEventSerializer serializer, IMessageTransport transport) { _logger = logger; _config = config; _serializer = serializer; _transport = transport; }
internal TestUnitOfWork(IAggregateRootRepository aggregateRootRepository, IEventStore eventStore, IEventDispatcher eventDispatcher, IDomainEventSerializer domainEventSerializer, IDomainTypeNameMapper domainTypeNameMapper) { _eventStore = eventStore; _eventDispatcher = eventDispatcher; _domainEventSerializer = domainEventSerializer; _realUnitOfWork = new RealUnitOfWork(aggregateRootRepository, domainTypeNameMapper); }
public CachingAggregateRootRepositoryDecorator(IAggregateRootRepository innerAggregateRootRepository, ISnapshotCache snapshotCache, IEventStore eventStore, IDomainEventSerializer domainEventSerializer) { _innerAggregateRootRepository = innerAggregateRootRepository; _snapshotCache = snapshotCache; _eventStore = eventStore; _domainEventSerializer = domainEventSerializer; }
/// <summary> /// 获取领域事件的序列器 /// </summary> /// <returns>领域事件序列器实例</returns> private static IDomainEventSerializer GetDomainEventSerializer() { IDomainEventSerializer serializer; // TODO: ReportMS.Framework.Events.Storage.DomainEventDataObject GetDomainEventSerializer //ApworksConfigSection config = AppRuntime.Instance.CurrentApplication.ConfigSource.Config; //if (config.Serializers == null || // config.Serializers.EventSerializer == null || // string.IsNullOrEmpty(config.Serializers.EventSerializer.Provider) || // string.IsNullOrWhiteSpace(config.Serializers.EventSerializer.Provider)) //{ // serializer = new DomainEventXmlSerializer(); //} //else //{ // string typeName = config.Serializers.EventSerializer.Provider; // var serializerType = Type.GetType(typeName); // if (serializerType == null) // throw new InfrastructureException("The serializer defined by type '{0}' doesn't exist.", typeName); // serializer = (IDomainEventSerializer)Activator.CreateInstance(serializerType); //} serializer = new DomainEventXmlSerializer(); return(serializer); }
public NewSnapshottingAggregateRootRepositoryDecorator(IAggregateRootRepository aggregateRootRepository, IEventStore eventStore, IDomainEventSerializer domainEventSerializer, ISnapshotStore snapshotStore, TimeSpan preparationThreshold) { _aggregateRootRepository = aggregateRootRepository; _eventStore = eventStore; _domainEventSerializer = domainEventSerializer; _snapshotStore = snapshotStore; _preparationThreshold = preparationThreshold; }
public FactoryBasedAggregateRootRepository(IEventStore eventStore, IDomainEventSerializer domainEventSerializer, IDomainTypeNameMapper domainTypeNameMapper, Func<Type, AggregateRoot> aggregateRootFactoryMethod) : base(eventStore, domainEventSerializer, domainTypeNameMapper) { if (aggregateRootFactoryMethod == null) throw new ArgumentNullException("aggregateRootFactoryMethod"); _aggregateRootFactoryMethod = aggregateRootFactoryMethod; }
internal TestContext(InMemoryEventStore eventStore, IAggregateRootRepository aggregateRootRepository, IEventDispatcher eventDispatcher, IDomainEventSerializer domainEventSerializer, ICommandMapper commandMapper, IDomainTypeNameMapper domainTypeNameMapper) { _eventStore = eventStore; _aggregateRootRepository = aggregateRootRepository; _eventDispatcher = eventDispatcher; _domainEventSerializer = domainEventSerializer; _testCommandMapper = commandMapper; _domainTypeNameMapper = domainTypeNameMapper; }
public FactoryBasedAggregateRootRepository(IEventStore eventStore, IDomainEventSerializer domainEventSerializer, IDomainTypeNameMapper domainTypeNameMapper, Func <Type, AggregateRoot> aggregateRootFactoryMethod) : base(eventStore, domainEventSerializer, domainTypeNameMapper) { if (aggregateRootFactoryMethod == null) { throw new ArgumentNullException("aggregateRootFactoryMethod"); } this._aggregateRootFactoryMethod = aggregateRootFactoryMethod; }
public InMemoryViewEventDispatcher( IEventStore eventStore, IAggregateRootRepository aggregateRootRepository, IDomainEventSerializer domainEventSerializer, IDomainTypeNameMapper domainTypeNameMapper) { _eventStore = eventStore; _aggregateRootRepository = aggregateRootRepository; _domainEventSerializer = domainEventSerializer; _domainTypeNameMapper = domainTypeNameMapper; }
/// <summary> /// Create a new instance of <see cref="DefaultMessageReceiver"/>. /// </summary> public DefaultMessageReceiver(IOptions <ServicebusConfiguration> options, ILogger <DefaultMessageReceiver> logger, IServiceProvider serviceProvider, IDomainEventSerializer serializer) { _configuration = options.Value; _logger = logger; _serviceProvider = serviceProvider; _serializer = serializer; // Prefetch the Deserialize method so we don't have to re-fetch it every time HandleIncoming is called. #pragma warning disable CS8601 // GetMethod might return null, but in this case can never do this (since we're using type safe nameof). _deserializeMethod = serializer.GetType().GetMethod(nameof(IDomainEventSerializer.DeserializeAsync)); #pragma warning restore CS8601 }
public SynchronousViewManagerEventDispatcher( IAggregateRootRepository aggregateRootRepository, IDomainEventSerializer domainEventSerializer, IDomainTypeNameMapper domainTypeNameMapper, params IViewManager[] viewManagers) { this.viewManagers = viewManagers.ToList(); _aggregateRootRepository = aggregateRootRepository; _domainEventSerializer = domainEventSerializer; _domainTypeNameMapper = domainTypeNameMapper; }
public SynchronousViewManagerEventDispatcher( IEventStore eventStore, IAggregateRootRepository aggregateRootRepository, IDomainEventSerializer domainEventSerializer, IDomainTypeNameMapper domainTypeNameMapper, params IViewManager[] viewManagers) { this.viewManagers = viewManagers.ToList(); _eventStore = eventStore; _aggregateRootRepository = aggregateRootRepository; _domainEventSerializer = domainEventSerializer; _domainTypeNameMapper = domainTypeNameMapper; }
/// <summary> /// 将给定的领域事件数据传输对象转化为相应的领域事件对象。 /// </summary> /// <param name="serializer"></param> /// <param name="from"></param> /// <returns>领域事件对象。</returns> public static IDomainEvent <TSourceId> ToDomainEvent <TSourceId>(this IDomainEventSerializer serializer, DomainEventDataObject <TSourceId> from) { if (string.IsNullOrEmpty(from.AssemblyQualifiedEventType)) { throw new InvalidDataException("form.AssemblyQualifiedTypeName"); } if (from.Data == null || from.Data.Length == 0) { throw new InvalidDataException("Data"); } var type = Type.GetType(from.AssemblyQualifiedEventType); var ret = (IDomainEvent <TSourceId>)serializer.Deserialize(type, from.Data); return(ret); }
internal TestContext(InMemoryEventStore eventStore, IAggregateRootRepository aggregateRootRepository, IEventDispatcher eventDispatcher, IDomainEventSerializer domainEventSerializer, ICommandMapper commandMapper, IDomainTypeNameMapper domainTypeNameMapper) { _eventStore = eventStore; _aggregateRootRepository = aggregateRootRepository; _eventDispatcher = eventDispatcher; _domainEventSerializer = domainEventSerializer; _testCommandMapper = commandMapper; _domainTypeNameMapper = domainTypeNameMapper; _viewManagerEventDispatcher = eventDispatcher as ViewManagerEventDispatcher; if (_viewManagerEventDispatcher != null) { _waitHandle.Register(_viewManagerEventDispatcher); } }
/// <summary> /// Initializes a new instance of the <c>RdbmsDomainEventStorage<TRdbmsStorage></c> class. /// </summary> /// <param name="domainEventSerializer"></param> /// <param name="connectionString">The connection string which is used when connecting /// to the relational database system. For more information about the connection strings /// for different database providers, please refer to http://www.connectionstrings.com. /// </param> /// <param name="mappingResolver">The instance of the mapping resolver which resolves the table and column mappings /// between data objects and the relational database system.</param> protected RdbmsDomainEventStorage(IDomainEventSerializer domainEventSerializer, string connectionString, IStorageMappingResolver mappingResolver) { try { this._domainEventSerializer = domainEventSerializer; this._connectionString = connectionString; this._mappingResolver = mappingResolver; Type storageType = typeof(TRdbmsStorage); _storage = (TRdbmsStorage)Activator.CreateInstance(storageType, new object[] { connectionString, mappingResolver }); } catch { GC.SuppressFinalize(this); throw; } }
/// <summary> /// Constructs the event dispatcher /// </summary> public DependentViewManagerEventDispatcher(IEnumerable <IViewManager> dependencies, IEnumerable <IViewManager> viewManagers, IEventStore eventStore, IDomainEventSerializer domainEventSerializer, IAggregateRootRepository aggregateRootRepository, IDomainTypeNameMapper domainTypeNameMapper, Dictionary <string, object> viewContextItems) { _dependencies = dependencies.ToList(); _viewManagers = viewManagers.ToList(); _eventStore = eventStore; _domainEventSerializer = domainEventSerializer; _aggregateRootRepository = aggregateRootRepository; _domainTypeNameMapper = domainTypeNameMapper; _viewContextItems = viewContextItems; _workerThread = new Thread(DoWork) { IsBackground = true }; _automaticCatchUpTimer.Elapsed += (o, ea) => _work.Enqueue(new Work()); _automaticCatchUpTimer.Interval = 1000; _maxDomainEventsPerBatch = 100; }
/// <summary> /// 根据给定的领域事件对象创建并初始化领域事件数据传输对象。 /// </summary> /// <param name="serializer"></param> /// <param name="entity">领域事件对象。</param> /// <returns>领域事件数据传输对象。</returns> public static DomainEventDataObject <TSourceId> FromDomainEvent <TSourceId>(this IDomainEventSerializer serializer, IDomainEvent <TSourceId> entity) { var obj = new DomainEventDataObject <TSourceId> { Branch = entity.Branch, Data = serializer.Serialize(entity), Id = entity.Id, AssemblyQualifiedEventType = string.IsNullOrEmpty(entity.AssemblyQualifiedEventType) ? entity.GetType().AssemblyQualifiedName : entity.AssemblyQualifiedEventType, Timestamp = entity.Timestamp, Version = entity.Version, SourceId = entity.Source.Id, AssemblyQualifiedSourceType = entity.Source.GetType().AssemblyQualifiedName }; return(obj); }
public CachingDomainEventSerializerDecorator(IDomainEventSerializer innerDomainEventSerializer, int approximateMaxNumberOfEntries) { _innerDomainEventSerializer = innerDomainEventSerializer; _approximateMaxNumberOfEntries = approximateMaxNumberOfEntries; _purgeTimer.Elapsed += delegate { try { PossiblyTrimCache(); } catch (Exception exception) { _log.Error(exception, "Eror while trimming cache"); } }; _purgeTimer.Start(); }
public ViewManagerEventDispatcher(IAggregateRootRepository aggregateRootRepository, IEventStore eventStore, IDomainEventSerializer domainEventSerializer, IDomainTypeNameMapper domainTypeNameMapper, params IViewManager[] viewManagers) { if (aggregateRootRepository == null) { throw new ArgumentNullException("aggregateRootRepository"); } if (eventStore == null) { throw new ArgumentNullException("eventStore"); } if (domainEventSerializer == null) { throw new ArgumentNullException("domainEventSerializer"); } if (domainTypeNameMapper == null) { throw new ArgumentNullException("domainTypeNameMapper"); } if (viewManagers == null) { throw new ArgumentNullException("viewManagers"); } _aggregateRootRepository = aggregateRootRepository; _eventStore = eventStore; _domainEventSerializer = domainEventSerializer; _domainTypeNameMapper = domainTypeNameMapper; viewManagers.ToList().ForEach(view => _viewManagers.Enqueue(view)); _worker = new Thread(DoWork) { IsBackground = true }; _automaticCatchUpTimer.Elapsed += delegate { _work.Enqueue(PieceOfWork.FullCatchUp(false)); }; AutomaticCatchUpInterval = TimeSpan.FromSeconds(1); }
public CachingDomainEventSerializerDecorator(IDomainEventSerializer innerDomainEventSerializer, int approximateMaxNumberOfEntries) { _innerDomainEventSerializer = innerDomainEventSerializer; _approximateMaxNumberOfEntries = approximateMaxNumberOfEntries; _purgeTimer.Elapsed += delegate { try { PossiblyTrimCache(); } catch (Exception exception) { _log.Error(exception, "Eror while trimming cache"); } }; _purgeTimer.Start(); }
public CommandProcessor( IEventStore eventStore, IAggregateRootRepository aggregateRootRepository, IEventDispatcher eventDispatcher, IDomainEventSerializer domainEventSerializer, ICommandMapper commandMapper, IDomainTypeNameMapper domainTypeNameMapper, Options options) { if (eventStore == null) { throw new ArgumentNullException("eventStore"); } if (aggregateRootRepository == null) { throw new ArgumentNullException("aggregateRootRepository"); } if (eventDispatcher == null) { throw new ArgumentNullException("eventDispatcher"); } if (domainEventSerializer == null) { throw new ArgumentNullException("domainEventSerializer"); } if (commandMapper == null) { throw new ArgumentNullException("commandMapper"); } if (domainTypeNameMapper == null) { throw new ArgumentNullException("domainTypeNameMapper"); } if (options == null) { throw new ArgumentNullException("options"); } _eventStore = eventStore; _aggregateRootRepository = aggregateRootRepository; _eventDispatcher = eventDispatcher; _domainEventSerializer = domainEventSerializer; _commandMapper = commandMapper; _domainTypeNameMapper = domainTypeNameMapper; _options = options; }
private static IDomainEventSerializer GetDomainEventSerializer() { IDomainEventSerializer serializer = null; string eventSerializerTypeName = ConfigurationManager.AppSettings["eventSerializer"]; if (eventSerializerTypeName == null) { serializer = new DomainEventXmlSerializer(); } else { Type serializerType = Type.GetType(eventSerializerTypeName); if (serializerType == null) { throw new InfrastructureException("The serializer defined by type '{0}' doesn't exist.", eventSerializerTypeName); } serializer = (IDomainEventSerializer)Activator.CreateInstance(serializerType); } return(serializer); }
public CommandProcessor( IEventStore eventStore, IAggregateRootRepository aggregateRootRepository, IEventDispatcher eventDispatcher, IDomainEventSerializer domainEventSerializer, ICommandMapper commandMapper, IDomainTypeNameMapper domainTypeNameMapper, Options options) { if (eventStore == null) throw new ArgumentNullException("eventStore"); if (aggregateRootRepository == null) throw new ArgumentNullException("aggregateRootRepository"); if (eventDispatcher == null) throw new ArgumentNullException("eventDispatcher"); if (domainEventSerializer == null) throw new ArgumentNullException("domainEventSerializer"); if (commandMapper == null) throw new ArgumentNullException("commandMapper"); if (domainTypeNameMapper == null) throw new ArgumentNullException("domainTypeNameMapper"); if (options == null) throw new ArgumentNullException("options"); _eventStore = eventStore; _aggregateRootRepository = aggregateRootRepository; _eventDispatcher = eventDispatcher; _domainEventSerializer = domainEventSerializer; _commandMapper = commandMapper; _domainTypeNameMapper = domainTypeNameMapper; _options = options; }
// crate and initializes the domain event data object from given domain event public static DomainEventDataObject FromDomainEvent(IDomainEvent @event) { IDomainEventSerializer serializer = GetDomainEventSerializer(); DomainEventDataObject domainEventDto = new DomainEventDataObject(); domainEventDto.Data = serializer.Serialize(@event); domainEventDto.Id = @event.Id; if (string.IsNullOrEmpty(@event.AssemblyQualifiedEventType)) { domainEventDto.AssemblyQualifiedEventType = @event.GetType().AssemblyQualifiedName; } else { domainEventDto.AssemblyQualifiedEventType = @event.AssemblyQualifiedEventType; } domainEventDto.Timestamp = @event.Timestamp; domainEventDto.Version = @event.Version; domainEventDto.SourceId = @event.Source.Id; domainEventDto.AssemblyQualifiedSourceType = @event.Source.GetType().AssemblyQualifiedName; return(domainEventDto); }
/// <summary> /// Creates and initializes the domain event data object from the given domain event. /// </summary> /// <param name="entity">The domain event instance from which the domain event data object /// is created and initialized.</param> /// <returns>The initialized data object instance.</returns> public static DomainEventDataObject FromDomainEvent(IDomainEvent entity) { IDomainEventSerializer serializer = GetDomainEventSerializer(); DomainEventDataObject obj = new DomainEventDataObject(); obj.Branch = entity.Branch; obj.Data = serializer.Serialize(entity); obj.ID = entity.ID; if (string.IsNullOrEmpty(entity.AssemblyQualifiedEventType)) { obj.AssemblyQualifiedEventType = entity.GetType().AssemblyQualifiedName; } else { obj.AssemblyQualifiedEventType = entity.AssemblyQualifiedEventType; } obj.Timestamp = entity.Timestamp; obj.Version = entity.Version; obj.SourceID = entity.Source.ID; obj.AssemblyQualifiedSourceType = entity.Source.GetType().AssemblyQualifiedName; return(obj); }
/// <summary> /// Gets the serializer for domain events. /// </summary> /// <returns>The domain event serializer instance.</returns> private static IDomainEventSerializer GetDomainEventSerializer() { IDomainEventSerializer serializer = null; ApworksConfigSection config = AppRuntime.Instance.CurrentApplication.ConfigSource.Config; if (config.Serializers == null || config.Serializers.EventSerializer == null || string.IsNullOrEmpty(config.Serializers.EventSerializer.Provider) || string.IsNullOrWhiteSpace(config.Serializers.EventSerializer.Provider)) { serializer = new DomainEventXmlSerializer(); } else { string typeName = config.Serializers.EventSerializer.Provider; Type serializerType = Type.GetType(typeName); if (serializerType == null) { throw new InfrastructureException("The serializer defined by type '{0}' doesn't exist.", typeName); } serializer = (IDomainEventSerializer)Activator.CreateInstance(serializerType); } return(serializer); }
/// <summary> /// Initializes a new instance of the domain event data object. /// </summary> public DomainEventDataObject() { this.serializer = GetDomainEventSerializer(); }
public DefaultAggregateRootRepository(IEventStore eventStore, IDomainEventSerializer domainEventSerializer, IDomainTypeNameMapper domainTypeNameMapper) { _eventStore = eventStore; _domainEventSerializer = domainEventSerializer; _domainTypeNameMapper = domainTypeNameMapper; }
/// <summary> /// Registers the given domain even serializer to be used instead of the default <see cref="JsonDomainEventSerializer"/>. /// </summary> public void UseCustomDomainEventSerializer(IDomainEventSerializer domainEventSerializer) { RegisterInstance(domainEventSerializer); }
public MySqlEventStore(MySqlServerConfiguration configuration, IDomainEventSerializer serializer) { this.serializer = serializer; this.configuration = configuration; Init(); }
public SqlServerEventStore(SqlServerConfiguration configuration, IDomainEventSerializer serializer) { this.serializer = serializer; this.configuration = configuration; Init(); }
/// <summary> /// Initializes a new instance of the domain event data object. /// </summary> public DomainEventDataObject() { this.serializer = GetDomainEventSerializer(); }
/// <summary> /// Gets the serializer for domain events. /// </summary> /// <returns>The domain event serializer instance.</returns> private static IDomainEventSerializer GetDomainEventSerializer() { IDomainEventSerializer serializer = null; ApworksConfigSection config = AppRuntime.Instance.CurrentApplication.ConfigSource.Config; if (config.Serializers == null || config.Serializers.EventSerializer == null || string.IsNullOrEmpty(config.Serializers.EventSerializer.Provider) || string.IsNullOrWhiteSpace(config.Serializers.EventSerializer.Provider)) { serializer = new DomainEventXmlSerializer(); } else { string typeName = config.Serializers.EventSerializer.Provider; Type serializerType = Type.GetType(typeName); if (serializerType == null) throw new InfrastructureException("The serializer defined by type '{0}' doesn't exist.", typeName); serializer = (IDomainEventSerializer)Activator.CreateInstance(serializerType); } return serializer; }
/// <summary> /// 获取领域事件的序列器 /// </summary> /// <returns>领域事件序列器实例</returns> private static IDomainEventSerializer GetDomainEventSerializer() { IDomainEventSerializer serializer; // TODO: ReportMS.Framework.Events.Storage.DomainEventDataObject GetDomainEventSerializer //ApworksConfigSection config = AppRuntime.Instance.CurrentApplication.ConfigSource.Config; //if (config.Serializers == null || // config.Serializers.EventSerializer == null || // string.IsNullOrEmpty(config.Serializers.EventSerializer.Provider) || // string.IsNullOrWhiteSpace(config.Serializers.EventSerializer.Provider)) //{ // serializer = new DomainEventXmlSerializer(); //} //else //{ // string typeName = config.Serializers.EventSerializer.Provider; // var serializerType = Type.GetType(typeName); // if (serializerType == null) // throw new InfrastructureException("The serializer defined by type '{0}' doesn't exist.", typeName); // serializer = (IDomainEventSerializer)Activator.CreateInstance(serializerType); //} serializer = new DomainEventXmlSerializer(); return serializer; }
public InMemoryEventStore(IDomainEventSerializer domainEventSerializer) { _domainEventSerializer = domainEventSerializer; }