Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CQRS - execute two handlers

I have a handler for creating a comments. And I have a second handler for creating a tasks.

Both handlers have implemented the same interface

public interface IHandle<TCommand>
{
      void Handle(TCommand);
}

Now, I need to create a comment right after a task was successfuly created. But on the other hand I still need the comment handler as a standalone handler.

So I'm wondering what would be the best solution for reusing the comment handler.

My first thought was simply injecting the comment handler into the task handler and then just call the comment handler inside the task handler Handle method.

My infrastructure is a ASP.NET MVC application where I resolve the handler using my IoC container and then execute the handler. I'm not using any message bus.

like image 909
user49126 Avatar asked Feb 01 '26 06:02

user49126


1 Answers

You can implement a TaskCreatedEvent handler that sends a CreateComment command once the TaskCreatedEvent has occurred. This basically is what would be called a Saga and coordinates processes across aggregate boundaries.

like image 147
Dennis Traub Avatar answered Feb 03 '26 23:02

Dennis Traub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!