Skip to content

Instantly share code, notes, and snippets.

@mhinze
Last active December 27, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhinze/7355152 to your computer and use it in GitHub Desktop.
Save mhinze/7355152 to your computer and use it in GitHub Desktop.
Sample ShortBus BaseController
using System.Web.Mvc;
using JetBrains.Annotations;
using ShortBus;
public abstract class BaseController : Controller
{
public IMediator Mediator { get; set; }
protected Response<TResult> Query<TResult>(IQuery<TResult> query)
{
return Mediator.Request(query);
}
protected void Command<T>(T command)
{
var result = Mediator.Send(command);
if (result.HasException())
{
throw result.Exception;
}
}
[AspMvcView]
protected ViewResult View<TData>(Response<TData> model)
{
return View(string.Empty, model);
}
protected ViewResult View<TData>([AspMvcView] string viewName, Response<TData> model)
{
if (model.HasException())
return base.View("~/Views/Shared/Error.cshtml", model);
return View(viewName, model.Data);
}
[AspMvcPartialView]
protected PartialViewResult PartialView<TData>(Response<TData> model)
{
return PartialView(string.Empty, model);
}
protected PartialViewResult PartialView<TData>([AspMvcPartialView] string viewName, Response<TData> model)
{
if (model.HasException())
return base.PartialView("~/Views/Shared/ErrorPartial.cshtml", model);
return PartialView(viewName, model.Data);
}
}
@model ShortBus.Response
@Html.Partial("ErrorPartial", Model)
@model ShortBus.Response
<div style="background: lightcoral; color: black">
@Model.Exception.ToString()
</div>
@mxmissile
Copy link

Do you see an issue with adding this overload?

protected ViewResult View<TData>(IQuery<TData> query)
{
        return View(Query(query));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment