question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is the best way of appling part of same logic in different handler?

See original GitHub issue
public 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:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

0reactions
valdisiljuconokscommented, Oct 19, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found