T
T
tison2018-02-13 12:50:51
C++ / C#
tison, 2018-02-13 12:50:51

How to make a command handler interface?

There are 2 types of commands in my code:
1. Returning a result
2. Not returning a result (Unit is a "dummy" type)

public interface ICommand : ICommand<Unit>{}
public interface ICommand<TResult>{}

At the moment, the handlers for these commands look like this:
public ICommandHandler<in TCommand> where TCommand : class, ICommand {
    Task Handle(TCommand command, CancellationToken cancellationToken = default(CancellationToken));
}

public ICommandHandler<in TCommand, TResult> where TCommand : class, ICommand<TResult> {
    Task<TResult> Handle(TCommand command, CancellationToken cancellationToken = default(CancellationToken));
}

I'd like to make these handlers part of the same type so that decorators can be written on top of all command types without code duplication.
How can I do that?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question