Add compatibility items for controller back from MVC 5
This commit is contained in:
parent
6fe663951d
commit
4baa2910b7
|
|
@ -8,25 +8,75 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Mvc.Core;
|
using Microsoft.AspNet.Mvc.Core;
|
||||||
|
using Microsoft.Framework.DependencyInjection;
|
||||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNet.Mvc.Rendering;
|
using Microsoft.AspNet.Mvc.Rendering;
|
||||||
|
using Microsoft.AspNet.Routing;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc
|
namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
public class Controller : IActionFilter, IAsyncActionFilter, IOrderedFilter
|
public class Controller : IActionFilter, IAsyncActionFilter, IOrderedFilter, IDisposable
|
||||||
{
|
{
|
||||||
private DynamicViewData _viewBag;
|
private DynamicViewData _viewBag;
|
||||||
|
private IViewEngine _viewEngine;
|
||||||
|
|
||||||
|
public IServiceProvider Resolver
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ActionContext?.HttpContext?.RequestServices;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public HttpContext Context
|
public HttpContext Context
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (ActionContext == null)
|
return ActionContext?.HttpContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpRequest Request
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ActionContext?.HttpContext?.Request;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpResponse Response
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ActionContext?.HttpContext?.Response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RouteData RouteData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ActionContext?.RouteData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IViewEngine ViewEngine
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_viewEngine == null)
|
||||||
{
|
{
|
||||||
return null;
|
_viewEngine = ActionContext?.
|
||||||
|
HttpContext?.
|
||||||
|
RequestServices.GetService<ICompositeViewEngine>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionContext.HttpContext;
|
return _viewEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_viewEngine = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,12 +84,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (ViewData == null)
|
return ViewData?.ModelState;
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ViewData.ModelState;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,12 +101,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (Context == null)
|
return Context?.User;
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Context.User;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,6 +183,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
ViewName = viewName,
|
ViewName = viewName,
|
||||||
ViewData = ViewData,
|
ViewData = ViewData,
|
||||||
|
ViewEngine = _viewEngine,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -622,5 +663,17 @@ namespace Microsoft.AspNet.Mvc
|
||||||
valueProvider,
|
valueProvider,
|
||||||
bindingContext.ValidatorProvider);
|
bindingContext.ValidatorProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[NonAction]
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(disposing: true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,11 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
Assert.DoesNotThrow(() => factory.ReleaseController(controller));
|
Assert.DoesNotThrow(() => factory.ReleaseController(controller));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MyController : Controller, IDisposable
|
private class MyController : Controller
|
||||||
{
|
{
|
||||||
public bool Disposed { get; set; }
|
public bool Disposed { get; set; }
|
||||||
public void Dispose()
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
Disposed = true;
|
Disposed = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue