public static IBusSubscriber SubscribeEvent <T>(this IBusSubscriber busSubscriber) where T : class, IEvent
 {
     return(busSubscriber.Subscribe <T>((sp, @event, ctx) =>
     {
         var commandHandler = sp.GetRequiredService <IEventHandler <T> >();
         return commandHandler.HandleAsync(@event);
     }));
 }
 public static IBusSubscriber SubscribeCommand <T>(this IBusSubscriber busSubscriber) where T : class, ICommand
 {
     return(busSubscriber.Subscribe <T>((sp, command, ctx) =>
     {
         var commandHandler = sp.GetRequiredService <ICommandHandler <T> >();
         return commandHandler.HandleAsync(command);
     }));
 }
示例#3
0
        public async Task <ActionResult <IEnumerable <string> > > Get()
        {
            try
            {
                await _publisher.PublishAsync(new ProductCreated()
                {
                    Id = Guid.NewGuid(), Name = "XXT"
                });

                _subscriber.Subscribe <ProductCreated>(async(serviceProvider, @event, _) =>
                {
                    await new ProductEventHandler().HandleAsync(@event);
                });
            }
            catch (Exception)
            {
                throw;
            }



            return(new List <string>());
        }
 public static IBusSubscriber SubscribeEvent <T>(this IBusSubscriber busSubscriber) where T : class, IEvent
 => busSubscriber.Subscribe <T>((sp, @event, ctx) => sp.GetService <IEventHandler <T> >().HandleAsync(@event));
 public static IBusSubscriber SubscribeCommand <T>(this IBusSubscriber busSubscriber) where T : class, ICommand
 => busSubscriber.Subscribe <T>((sp, command, ctx) => sp.GetService <ICommandHandler <T> >().HandleAsync(command));
 public Task Subscribe(Func <TMessage, CancellationToken, Task> messageHandler, CancellationToken cancellationToken)
 {
     return(_busSubscriber.Subscribe(messageHandler, cancellationToken));
 }