示例#1
0
        /// <inheritdoc />
        public async Task PublishAsync <TEvent>(TEvent @event) where TEvent : IEvent
        {
            if (@event == null)
            {
                throw new ArgumentNullException(nameof(@event));
            }

            var handlers = _resolver.ResolveAll <IEventHandlerAsync <TEvent> >();

            foreach (var handler in handlers)
            {
                await handler.HandleAsync(@event);
            }

            if (@event is IBusMessage message)
            {
                await _busMessageDispatcher.DispatchAsync(message);
            }
        }
示例#2
0
        /// <inheritdoc />
        public void Publish <TEvent>(TEvent @event) where TEvent : IEvent
        {
            if (@event == null)
            {
                throw new ArgumentNullException(nameof(@event));
            }

            var handlers = _resolver.ResolveAll <IEventHandler <TEvent> >();

            foreach (var handler in handlers)
            {
                handler.Handle(@event);
            }

            if (@event is IBusMessage message)
            {
                _busMessageDispatcher.DispatchAsync(message).GetAwaiter().GetResult();
            }
        }
示例#3
0
        public async Task PublishAsync <TEvent>(TEvent @event) where TEvent : IEvent
        {
            if (@event == null)
            {
                throw new ArgumentNullException(nameof(@event));
            }

            _userContext = @event.UserContext;

            //TODO there is a probability to have multiple handlers
            var handler = _handlerResolver.ResolveHandler(@event, typeof(IEventHandlerAsync <>));

            //TODO inmemory handler is not triggering
            if (handler != null)
            {
                await handler.AsDynamic().HandleAsync(@event);
            }

            if (@event is IBusTopicMessage message)
            {
                await _busMessageDispatcher.DispatchAsync(message);
            }
        }
示例#4
0
 /// <inheritdoc />
 public Task DispatchBusMessageAsync <TMessage>(TMessage message)
     where TMessage : IBusMessage
 {
     return(_busMessageDispatcher.DispatchAsync(message));
 }
 public Task SendBusMessageAsync <TMessage>(TMessage message) where TMessage : IMessage
 {
     SetUserContextWithMessage(message);
     return(_busMessageDispatcher.DispatchAsync(message));
 }