Skip to content

Instantly share code, notes, and snippets.

@benfoster
Created June 16, 2012 09:38
Show Gist options
  • Save benfoster/2940739 to your computer and use it in GitHub Desktop.
Save benfoster/2940739 to your computer and use it in GitHub Desktop.
ASP.NET MVC Controller Scaffolding
public class MyController {
private readonly IViewFactory viewFactory;
private readonly ICommandBus bus;
public MyController(IViewFactory viewFactory, ICommandBus bus) {
this.viewFactory = viewFactory;
this.bus = bus;
}
[HttpGet]
public ActionResult List(ListInputModel input) {
var model = viewFactory.Create<ListView>(input);
return View(model);
}
[HttpPost]
[ValidateModelState] // saves the usual if ModelState.IsValid junk
public ActionResult Create(CreateInputModel model) {
var cmd = new CreateCommand {
Name = model.Name
};
bus.Send(cmd);
return RedirectToAction("list");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment