dimanche 18 juin 2023

How to manage update command using CQRS pattern for multiple scenarios?

I am using the CQRS pattern and have come across a scenario where I need some help. To understand the issue let's say we have an entity User which has UserId, FirstName, LastName.... in an application AppA I only need to update the FirstName and for this, I have the below command:

public sealed record UpdateUserCommand(int UserId, string FirstName) : IRequest

Then I have another application AppB that another developer is working on and he is sharing the library using the CQRS pattern. From AppB the developer wants to update FirstName & LastName. The above command is changed to:

public sealed record UpdateUserCommand(int UserId, string FirstName, LastName) : IRequest

This change has broken my code in AppA. I need help to understand what is the best practice to handle such a situation. If I am understanding the CQRS correctly then shouldn't be the all commands be specific for each scenario and in this case I need to have two commands as follow?

public sealed record UpdateUserFirstNameCommand(int UserId, string FirstName) : IRequest

public sealed record UpdateUserFullNameCommand(int UserId, string FirstName, LastName) : IRequest

shouldn't I use them in each separate application? Please help me with how should I implement it.

Thanks.

Aucun commentaire:

Enregistrer un commentaire