Skip to content

Instantly share code, notes, and snippets.

@kristofclaes
Last active December 24, 2015 23:59
Show Gist options
  • Save kristofclaes/6884007 to your computer and use it in GitHub Desktop.
Save kristofclaes/6884007 to your computer and use it in GitHub Desktop.
public class InschrijvingenController : Controller
{
private readonly ICommandDispatcher dispatcher;
public InschrijvingenController(ICommandDispatcher dispatcher)
{
this.dispatcher = dispatcher;
}
public ActionResult Create(CreateModel model)
{
RegistreerNieuweInschrijvingCommand command = CreateCommand(model);
dispatcher.ExecuteCommand(command);
return RedirectToAction("Index");
}
private RegistreerNieuweInschrijvingCommand CreateCommand(CreateModel model) { ... }
}
public interface ICommandDispatcher
{
void ExecuteCommand<T>(T command) where T : class;
}
public class CommandDispatcher
{
private readonly IKernel kernel;
public CommandDispatcher(IKernel kernel)
{
this.kernel = kernel;
}
public void ExecuteCommand<T>(T command) where T : class
{
var handler = kernel.Get<ICommandHandler<T>>();
handler.Handle(command);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment