In my System.Web.Mvc Action filters I previously used TempData to store an instance of my unitOfWork service like so:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.Controller.TempData[UnitOfWorkRequestKey] = UnitOfWork;
UnitOfWork.Begin();
}
then to commit the transaction I retreived it from temp data like this..
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
var unitOfWork = (IUnitOfWork)filterContext.Controller.TempData[UnitOfWorkRequestKey];
try
{
if (filterContext.Exception == null)
{
unitOfWork.Complete();
}
}
finally
{
unitOfWork.Dispose();
filterContext.Controller.TempData[UnitOfWorkRequestKey] = null;
}
}
So my question is:
In the System.Web.Http
Web Api Action Filter (using HttpActionContext
) - is there an equivalent location to store my instance of a service, so I can retrieve the same instance when the action has executed?