MessageRouter icon indicating copy to clipboard operation
MessageRouter copied to clipboard

Using a single class to implement multiple handlers throws "AmbiguousMatchException".

Open ctigeek opened this issue 8 years ago • 1 comments

Let's say I have two classes that implement ICommand: TestCommand1 and TestCommand2. The following handler will cause the router to throw an "AmbiguousMatchException":

public class TestCommandHandler : IHandleCommand<TestCommand1>, IHandleCommand<TestCommand2>
    {
        public Task Handle(TestCommand1 command, CancellationToken shutdown)
        {
            Console.WriteLine(command.SomeText);
            return Task.FromResult<object>(null);
        }

        public Task Handle(TestCommand2 command, CancellationToken shutdown)
        {
            Console.WriteLine(command.SomeText);
            return Task.FromResult<object>(null);
        }
    }

If the handlers are segregated into separate classes, it doesn't throw this exception. However it can certainly be desirable to group handlers in the same class. Thanks.

Edit: fixed typo, added formatting.

ctigeek avatar Mar 12 '16 14:03 ctigeek