示例#1
0
        public async Task UpdateAsync(Product entity, CancellationToken ct)
        {
            await _productRepository.UpdateAsync(entity, ct);

            await SaveChangesAsync(ct);

            await _eventStoreService.Save(entity);
        }
        public async Task Publish <T>(T @event) where T : Event
        {
            if ([email protected](nameof(DomainNotification)))
            {
                await _eventStore.Save(@event);
            }

            await _mediator.Publish(@event);
        }
示例#3
0
        public Task RaiseEvent <T>(T @event) where T : Event
        {
            if ([email protected]("DomainNotification"))
            {
                _eventStore?.Save(@event);
            }

            return(_mediator.Publish(@event));
        }
示例#4
0
 /// <summary>
 /// 引发事件的实现方法 /// </summary>
 /// <typeparam name="T">泛型 继承 Event:INotification</typeparam>
 /// <param name="event">事件模型,比如StudentRegisteredEvent</param>
 /// <returns></returns>
 public Task RaiseEvent <T>(T @event) where T : Event
 {
     //除了领域通知以外 的事件都保存下来
     if ([email protected]("DomainNotification"))
     {
         _eventStoreService?.Save(@event); //MediatR中介者模式中的第二种方法,发布 / 订阅模式
     }
     return(_mediator.Publish(@event));
 }
示例#5
0
        /// <summary>
        /// 发布事件通知
        /// </summary>
        /// <typeparam name="TNotification"></typeparam>
        /// <param name="event">通知事件</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task PublishEvent <TNotification>(TNotification @event, CancellationToken cancellationToken = default(CancellationToken)) where TNotification : Event
        {
            // 除了领域通知以外的事件都保存下来
            if ([email protected]("DomainNotification"))
            {
                eventStoreService?.Save(@event);
            }

            // MediatR中介者模式中的第二种方法,发布/订阅模式
            return(mediator.Publish(@event));
        }
示例#6
0
        public async Task ManageEvent(IAggregateInfo aggregateInfo, int eventVersion, IEvent e)
        {
            var dto = EventStoreMapper.EventMapper(aggregateInfo, eventVersion, e);

            try
            {
                await _service.Save(dto);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#7
0
        public async Task ManageEvent(IAggregateInfo aggregateInfo, int eventVersion, IEvent e)
        {
            var dto = EventStoreMapper.EventMapper(aggregateInfo, eventVersion, e);

            try
            {
                await _service.Save(dto);

                _presenter.PublishAmountDeposited(dto.AggregateId, dto.AggregateData);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#8
0
        public async Task ManageEvent(IAggregateInfo aggregateInfo, int eventVersion, IEvent e)
        {
            var dto = EventStoreMapper.EventMapper(aggregateInfo, eventVersion, e);

            try
            {
                await _service.Save(dto);

                _presenter.PublishAccountCreated(dto.AggregateId, dto.AggregateData);
            }
            catch (Exception ex)
            {
                _presenter.PublishErrorCreatingAccount(ex.Message);
                throw;
            }
        }
示例#9
0
        /// <summary>
        /// 发布事件
        /// </summary>
        /// <param name="eventEntity"></param>
        public void Publish(AbstractEvent eventEntity)
        {
            IList <IEventObserver> eventObservers = eventObserverProvider.GetEventObservers();

            foreach (IEventObserver eventObserver in eventObservers)
            {
                if (eventObserver.Support(eventEntity.GetType()))
                {
                    try
                    {
                        eventObserver.Receive(eventEntity);
                    }
                    catch (Exception ex)
                    {
                        eventStoreService.Save(eventEntity, ex);
                    }
                }
            }
        }
示例#10
0
 public async Task Save(EventStoredDTO e)
 {
     await _service.Save(e);
 }
示例#11
0
 public async Task <ActionResult> Create([FromBody] CreateEventStoreDto createEventStoreDto)
 {
     return(Ok(await _evenStoreService.Save(createEventStoreDto)));
 }
示例#12
0
 public Task <R> SendCommand <T, R>(T command) where T : Command <R>
 {
     //存储所有的领域命令
     Task.Run(() => _eventStoreService.Save(command));
     return(_mediator.Send(command));
 }