You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a situation where commands are serialized and pushed on a command queue, how can we call the appropriate handler after de-serialization?
// In publisher processvarcommand=newCreateUserCommand.Command("[email protected]");commandQueue.Push((JsonSerializer.Serialize(command),command.GetType()));// ...// In consumer process(stringcommandRaw,TypecommandType)=commandQueue.Pop();varcommand=JsonSerializer.Deserialize(commandRaw,commandType);awaithandlerInvoker.InvokeHandlerAsync(command);// <- suggested API
A work-around would be to try to resolve a IHandler<TCommand, ValueTuple> from the DI container since we know TCommand but it gets ugly. Also there is no guarantee that the handler was actually implemented as a Command handler so the response type might be unknown (and irrelevant, we just want to run the handler).
This is close to the MediatR API where you can execute a handler simply by knowing the command object: mediator.Send(command).
The text was updated successfully, but these errors were encountered:
In a situation where commands are serialized and pushed on a command queue, how can we call the appropriate handler after de-serialization?
A work-around would be to try to resolve a
IHandler<TCommand, ValueTuple>
from the DI container since we knowTCommand
but it gets ugly. Also there is no guarantee that the handler was actually implemented as a Command handler so the response type might be unknown (and irrelevant, we just want to run the handler).This is close to the
MediatR
API where you can execute a handler simply by knowing the command object:mediator.Send(command)
.The text was updated successfully, but these errors were encountered: