What is the best way of appling part of same logic in different handler?
See original GitHub issuepublic class InvoiceCreateCommandHandlerAsync: AsyncRequestHandler<InvoiceCreateCommand>
{
private readonly DbContext _db;
public InvoiceCreateCommandHandlerAsync(
DbContext db)
{
_db= db;
}
protected override async Task HandleCore(InvoiceCreateCommand command)
{
//Transaction
//Save Invoice DB action
//As the invoice is added, and the stock will be stocked out
//Stock out Logic here
.......
//End
//Commit
}
}
public class StockOutCommandHandlerAsync: AsyncRequestHandler<StockOutCommand>
{
private readonly DbContext _db;
public StockOutCommandHandlerAsync(
DbContext db)
{
_db= db;
}
protected override async Task HandleCore(StockOutCommand command)
{
//Stock out Logic here
.......
//End
}
}
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
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Dealing with Duplication in MediatR Handlers
One approach I've seen for either duplication is to have common query/command handlers, so that my handler calls MediatR or some other handler....
Read more >design - Passing an object between different handlers or a ...
Pass O from handler to handler, and manage the transitions between states, and keep some sort of info in O saying which states...
Read more >Domain Command Patterns - Handlers
This raises the question - where should this logic go? We can look at a number of design patterns (including the Command Object...
Read more >Are CQRS commands part of the domain model?
Example - I can have two commands AddOrderCommand and AddSimplifiedOrderCommand and both handlers will execute the same Aggregate Method ...
Read more >10 Creating and Using SOAP Message Handlers
Each handler in a handler chain may define methods for both inbound and outbound messages. Typically, each SOAP message handler defines a separate...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://lostechies.com/jimmybogard/2016/12/12/dealing-with-duplication-in-mediatr-handlers/
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.