Exemplo n.º 1
0
 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);
     }));
 }
Exemplo n.º 2
0
 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);
     }));
 }
Exemplo n.º 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));
 }