Created
September 29, 2016 12:52
-
-
Save ritasker/0a2f5a3b44248641afba1d2905fe41c2 to your computer and use it in GitHub Desktop.
CommandHandler classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class CommandHandler<TCommand, TResult> where TCommand : ICommand<TResult> | |
{ | |
public abstract TResult Handle(TCommand command); | |
} | |
public class SomeCommandeHandler : CommandHandler<SomeCommand, Guid> | |
{ | |
public override Guid Handle(SomeCommand command) | |
{ | |
// Do stuff here | |
return Guid.NewGuid(); | |
} | |
} | |
public class SimpleInjectorCommandHandlerResolver : ICommandHandlerResolver | |
{ | |
private readonly Container _container; | |
public SimpleInjectorCommandHandlerResolver(Container container) | |
{ | |
_container = container; | |
} | |
public CommandHandler<ICommand<TResult>, TResult> ResolveForCommand<TResult>(ICommand<TResult> command) | |
{ | |
var handlerType = typeof(CommandHandler<,>).MakeGenericType(command.GetType(), typeof(TResult)); | |
return (CommandHandler<ICommand<TResult>, TResult>) _container.GetInstance(handlerType); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment