Beispiel #1
0
        public async Task Publish_and_handle_InternalEvent()
        {
            var agr    = CreateAppleAgr("Green");
            var @event = agr.GetUncommittedEvents().First();

            var s  = _provider.GetRequiredService <IInternalEventHandler <AppleCreated> >();
            var ss = _provider.GetServices <IInternalEventHandler <AppleCreated> >();

            await _internalEventPublisher.PublishAsync(@event);


            Assert.True(AppleCreatedEventHandler.IsHandled);
        }
Beispiel #2
0
        public async Task SaveAsync(TA aggregateRoot, CancellationToken cancellationToken = default)
        {
            var events = aggregateRoot.FlushUncommittedEvents();

            if (!events.Any())
            {
                return;
            }

            await _eventStore.AppendAsync(events, cancellationToken);

            try
            {
                await _eventPublisher.PublishAsync(events, cancellationToken);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }