Skip to content

Support for handler resolution/invocation without knowing response type #163

Open
@CocoDico78

Description

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 process
var command = new CreateUserCommand.Command("[email protected]");
commandQueue.Push((JsonSerializer.Serialize(command), command.GetType()));

// ...

// In consumer process
(string commandRaw, Type commandType) = commandQueue.Pop();
var command = JsonSerializer.Deserialize(commandRaw, commandType);

await handlerInvoker.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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions