Hello.
I ran into the following problem. I have base message DebitAccount. I have created DepositMoney that inherits from DebitAccount.
The problem is that the handler gets called twice. How can i prevent it from being called twice?
Hello.
I ran into the following problem. I have base message DebitAccount. I have created DepositMoney that inherits from DebitAccount.
The problem is that the handler gets called twice. How can i prevent it from being called twice?
Looking at diagnostics it has the following:
"CustomerService.Command.ApplicationService.Accounts.DebitAccountHandler",
"CustomerService.Command.ApplicationService.Accounts.DepositMoneyHandler"
],
I want DepositCustomerMoney to only be handled by DepositMoneyHandler. How can I fix that issue?
Thanks
Hi @ekjuanrejon,
if DepositMoney
inherits from DebitAccount
the behavior you’re observing is the expected one: an endpoint containing a message handler for the base type and for the derived type will invoke the base type handler for all the incoming messages matching that type. In your scenario, given that DepositMoney
inherits from a base type when handled the handler for the base type will be invoked too.
Before thinking about a solution, let me ask a couple of questions:
Cheers,
.m
@mauroservienti I want to disable that feature. The reason I have base command is to use generic in my domain layer. I don’t want the handler to be execute multiple times
Because there are time…I just want to debit and account and trigger and event. But when it is a deposit I want to trigger a fine grain event for other systems to react. Right now DepositMoney execute both handler and customer account money is doubled
Thanks for the details. That’s the default inheritance behavior, and there is no way to disable it. There are a couple of solutions:
//in the base message handler
if(message.GetType() is typeof(DerivedType))
{
//skips the execution of this handler
return;
}