This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi - when I use LightSpeedControllerBase<T> for my controllers - the ViewBag property isn't available in an MVC 3 project. Is this because the controller base inherits from an MVC 2 controller class? If so - is there a workaround? Thanks, Phil |
|
|
Hi Phil, Yes - thats correct that the LightSpeedControllerBase<T> inherits from the MVC2 controller, its compiled against the MVC2 binaries so that it can support both 2 and 3. If you want a V3 specific controller base you will need to implement your own version of the controller. Here is a code sample which you can use
public abstract class LightSpeedMvc3ControllerBase<TUnitOfWork> : Controller where TUnitOfWork : class, Mindscape.LightSpeed.IUnitOfWork, new() { private UnitOfWorkScopeBase<TUnitOfWork> _unitOfWorkScope; private bool _autoDispose = true;
private UnitOfWorkScopeBase<TUnitOfWork> UnitOfWorkScope { get { if (_unitOfWorkScope == null) { _unitOfWorkScope = new PerRequestUnitOfWorkScope<TUnitOfWork>(LightSpeedContext); }
return _unitOfWorkScope; } }
protected abstract LightSpeedContext<TUnitOfWork> LightSpeedContext { get; }
protected TUnitOfWork UnitOfWork { get { return UnitOfWorkScope.Current; } }
public bool DisposeUnitOfWorkOnResultExecuted { get { return _autoDispose; } set { _autoDispose = value; } }
protected override void OnResultExecuted(ResultExecutedContext filterContext) { DisposeUnitOfWorkScope();
base.OnResultExecuted(filterContext); }
protected override void Dispose(bool disposing) { if (disposing) { DisposeUnitOfWorkScope(); }
base.Dispose(disposing); }
private void DisposeUnitOfWorkScope() { if (_autoDispose && _unitOfWorkScope != null && _unitOfWorkScope.HasCurrent) { _unitOfWorkScope.Current.Dispose(); } } }
Jeremy |
|
|
Thanks - I'll give it a spin. |
|