-
Is your feature request related to a problem? Please describe. Describe the solution you'd like Describe alternatives you've considered I would make totally sense to me if we could return a different type: Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
Hey @IlSocio. I just moved this over to "Discussions" as it feels more appropriate as a Q&A type thing. One reason (the may be others intended) is so that you can access properties on the Command that might have been mutated as part of the handler. For example you have a
This is actually how Darker works, and is more suited to the query side of CQRS. |
Beta Was this translation helpful? Give feedback.
-
Thanks @DevJonny, the use-case you mentioned makes sense. |
Beta Was this translation helpful? Give feedback.
-
Brighter does two things:
What Brighter is not is a mediator => which is a collaborator between colleagues, for example within a domain: (see https://softwareengineering.stackexchange.com/questions/364139/what-is-the-difference-between-the-command-and-mediator-patterns) As we can have a number of orthogonal elements that run before the domain code, and may wish to re-use them, we use the pipes-and-filters approach to middleware. In pipes and filters we have a source - in our case the command processor putting the request into the pipeline and a sink - the domain code. In between you can insert filter steps - middleware. As with most implementations of the filter pattern, to allow arbitrary composition, where you have an input and an output, and want to allow arbitrary composition of filter chains - both in order and in type - you need to make the input and output the same. Once input and output are the same, you can make the input of one filter, the output of another filter, allowing them to be chained together. This is not true if the input is not the output. Incidentally, because the request being sent down the chain - the information packet - is both output and input we are comfortable with having fields on it that are filled by some part of the chain, not by the source. A typical usage here is when the source cannot decide the id of any entity that will be created, but we want to access it after the pipeline runs. By putting id on the request, we can read it afterwards. A reasonable question might be why Send and Publish don't return TRequest? That might be a change that we could make. Now of course by the time the pipeline terminates, the pass-by-reference approach of C# means that the original request already has all of the modifications, so we don't need to. But arguably this is true throughout the pipeline but we included a return value to make it clearer that mutation was possible. So if it was clearer to have TRequest as the return type, perhaps in v10. We don't really want to modify this to change TRequest into TResponse here for this reason. Now Darker does do TRequest to TRespone. Why the difference? Because Brighter is the "command" operation i.e. how we mutate state and Darker is the "query" operation, how we read state. Apart from "get of jail" uses such as "what is the id of the newly created entity" we don't recommend using Brighter to return state in its TRequest to the caller. What happens in the pipeline stays in the pipeline. Instead we recommend using Brighter to change it and Darker to read it. This separation is Command Query Separation (CQS): https://en.wikipedia.org/wiki/Command%E2%80%93query_separation Does that help at all? We have a fundamental difference of approach here to Mediatr (its not a mediator and it mixes commands and queries) |
Beta Was this translation helpful? Give feedback.
-
PS Technically we can run middleware after your domain code. Because of the Russian doll model you mostly don't need to do that explicitly very often as you just run your code after calling the next handler in the chain not before. But if, for whatever reason, you really want to run the middleware after the domain handler, you can. It's just about flexibility, but its not usually a recommendation. |
Beta Was this translation helpful? Give feedback.
-
thank you a lot for the detailed explaination @iancooper. |
Beta Was this translation helpful? Give feedback.
Brighter does two things:
What Brighter is not is a mediator => which is a collaborator between colleagues, for example within a domain: (see https://softwareengineering.stackexchange.com/questions/364139/what-is-the-difference-between-the-command-and-mediator-patterns)
As we can have a number of orthogonal elements that run before the domai…