C
C#13mo ago
M B V R K

✅ Is this a correct way or I just mad things wrong?

Hi friends, hope you're doing well, I'm working on a project which using CQRS with MediatR, I have a PipelineBehavior for handling exception happened in the Commands and Queries, Lets talk in a brief manner about Commands, most of Commands in this project are returning a result ( type ) inherited from CommandResult<TValue, TCommandResultclass, that class used to implement the Result Pattern, How should this work usually? Before, every Command if executed successfully it should return a result ( its type inherited from CommandResult<TValue, TCommandResult) that represents a succeeded operation, but in an Exception situation the command should return a result ( its type inherited from CommandResult<TValue, TCommandResult) that represents a failed operation, and both Faild and Succeeededare the same type. What I did? I removed the exception handling from commands, and moved itt to that PiplineBehavior, So that behavior should execute the command, if it executed successfully, then its fine, but if an exception happened it will check which TResponse related to the request and create a Failed result then return iit. Please take a look on that behavior here : https://github.com/MbarkT3STO/ExpenovaApp/blob/20c83b6076e197af5097c6c862db6ad9e7d0d42e/Source/ExpenseService/ExpenseService.Application/Behaviors/ExceptionHandlingBehavior.cs Where is the issue here? The issue is a method called CreateFailedResult iit checks and returns the correct result, and the issue is that method checks all the commands and also queries, nd as you will notice that at this moment there are many ifs there, and in the future handreds of commands and queries will be added. The question: Is this technique I used here has a value or I just did things wrong ? Is there any other way to do the same ? Do you have any suggestion about this situation ? Massive thanks in advance, with love <3
4 Replies
Anu6is
Anu6is13mo ago
didn't you post this before?
M B V R K
M B V R KOP13mo ago
Yeah, but get no answers
M B V R K
M B V R KOP13mo ago
Thanks to Github Copilot
No description
Want results from more Discord servers?
Add your server