Closed vip30 closed 7 years ago
You can inject a helper into both handlers and call shared logic method from there
I see we can inject a service/helper for helping the stock out function, but it will not be treated as a command (But it will insert in the DB) , I just want to know is that violate the CQRS pattern with mediatR? Many Thanks
I don't think a handler to have a dependency is illegal, and injecting it into its ctor violates any principle. Rather follows these principles. Also it's better than inheriting both handlers from a base class (see the composition over inheritance principle)
Hi, I would think of StockOut
logic as code fragment that does not need to treated as command separately, but it's always called from the "hosting" command -> one or another handler. StockOut
code fragment makes no sense by itself, but is always executed within the command. And handler having a dependency - don't think it's illegal. Think about it as ordinary service injection for the handler.
Sorry about the poor format. I would like to ask what is the best approach for applying same logic in different handler? As the stock out logic is need to provide in create invoice and also in the stock out page Thanks