Use sealed contexts for ActionInvoker
This commit is contained in:
parent
c5e9904f57
commit
3eca32965d
|
|
@ -21,8 +21,8 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
|
|
||||||
private Dictionary<string, object> _arguments;
|
private Dictionary<string, object> _arguments;
|
||||||
|
|
||||||
private ActionExecutingContext _actionExecutingContext;
|
private ActionExecutingContextSealed _actionExecutingContext;
|
||||||
private ActionExecutedContext _actionExecutedContext;
|
private ActionExecutedContextSealed _actionExecutedContext;
|
||||||
|
|
||||||
internal ControllerActionInvoker(
|
internal ControllerActionInvoker(
|
||||||
ILogger logger,
|
ILogger logger,
|
||||||
|
|
@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
if (_actionExecutingContext == null)
|
if (_actionExecutingContext == null)
|
||||||
{
|
{
|
||||||
_actionExecutingContext = new ActionExecutingContext(_controllerContext, _filters, _arguments, _instance);
|
_actionExecutingContext = new ActionExecutingContextSealed(_controllerContext, _filters, _arguments, _instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
state = current.FilterAsync;
|
state = current.FilterAsync;
|
||||||
|
|
@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
if (_actionExecutingContext == null)
|
if (_actionExecutingContext == null)
|
||||||
{
|
{
|
||||||
_actionExecutingContext = new ActionExecutingContext(_controllerContext, _filters, _arguments, _instance);
|
_actionExecutingContext = new ActionExecutingContextSealed(_controllerContext, _filters, _arguments, _instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
state = current.Filter;
|
state = current.Filter;
|
||||||
|
|
@ -143,7 +143,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
// If we get here then the filter didn't call 'next' indicating a short circuit.
|
// If we get here then the filter didn't call 'next' indicating a short circuit.
|
||||||
_logger.ActionFilterShortCircuited(filter);
|
_logger.ActionFilterShortCircuited(filter);
|
||||||
|
|
||||||
_actionExecutedContext = new ActionExecutedContext(
|
_actionExecutedContext = new ActionExecutedContextSealed(
|
||||||
_controllerContext,
|
_controllerContext,
|
||||||
_filters,
|
_filters,
|
||||||
_instance)
|
_instance)
|
||||||
|
|
@ -189,7 +189,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
// Short-circuited by setting a result.
|
// Short-circuited by setting a result.
|
||||||
_logger.ActionFilterShortCircuited(filter);
|
_logger.ActionFilterShortCircuited(filter);
|
||||||
|
|
||||||
_actionExecutedContext = new ActionExecutedContext(
|
_actionExecutedContext = new ActionExecutedContextSealed(
|
||||||
_actionExecutingContext,
|
_actionExecutingContext,
|
||||||
_filters,
|
_filters,
|
||||||
_instance)
|
_instance)
|
||||||
|
|
@ -255,7 +255,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
if (_actionExecutedContext == null)
|
if (_actionExecutedContext == null)
|
||||||
{
|
{
|
||||||
_actionExecutedContext = new ActionExecutedContext(_controllerContext, _filters, _instance)
|
_actionExecutedContext = new ActionExecutedContextSealed(_controllerContext, _filters, _instance)
|
||||||
{
|
{
|
||||||
Result = _result,
|
Result = _result,
|
||||||
};
|
};
|
||||||
|
|
@ -301,7 +301,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
_actionExecutedContext = new ActionExecutedContext(_controllerContext, _filters, _instance)
|
_actionExecutedContext = new ActionExecutedContextSealed(_controllerContext, _filters, _instance)
|
||||||
{
|
{
|
||||||
ExceptionDispatchInfo = ExceptionDispatchInfo.Capture(exception),
|
ExceptionDispatchInfo = ExceptionDispatchInfo.Capture(exception),
|
||||||
};
|
};
|
||||||
|
|
@ -323,7 +323,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
invoker._actionExecutedContext = new ActionExecutedContext(invoker._controllerContext, invoker._filters, invoker._instance)
|
invoker._actionExecutedContext = new ActionExecutedContextSealed(invoker._controllerContext, invoker._filters, invoker._instance)
|
||||||
{
|
{
|
||||||
ExceptionDispatchInfo = ExceptionDispatchInfo.Capture(exception),
|
ExceptionDispatchInfo = ExceptionDispatchInfo.Capture(exception),
|
||||||
};
|
};
|
||||||
|
|
@ -349,7 +349,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Assert(_actionExecutedContext != null);
|
Debug.Assert(_actionExecutedContext != null);
|
||||||
return Task.FromResult(_actionExecutedContext);
|
return Task.FromResult<ActionExecutedContext>(_actionExecutedContext);
|
||||||
|
|
||||||
static async Task<ActionExecutedContext> Awaited(ControllerActionInvoker invoker, Task task)
|
static async Task<ActionExecutedContext> Awaited(ControllerActionInvoker invoker, Task task)
|
||||||
{
|
{
|
||||||
|
|
@ -485,7 +485,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Rethrow(ActionExecutedContext context)
|
private static void Rethrow(ActionExecutedContextSealed context)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
|
|
@ -567,5 +567,15 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
ActionInside,
|
ActionInside,
|
||||||
ActionEnd,
|
ActionEnd,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private sealed class ActionExecutingContextSealed : ActionExecutingContext
|
||||||
|
{
|
||||||
|
public ActionExecutingContextSealed(ActionContext actionContext, IList<IFilterMetadata> filters, IDictionary<string, object> actionArguments, object controller) : base(actionContext, filters, actionArguments, controller) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class ActionExecutedContextSealed : ActionExecutedContext
|
||||||
|
{
|
||||||
|
public ActionExecutedContextSealed(ActionContext actionContext, IList<IFilterMetadata> filters, object controller) : base(actionContext, filters, controller) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue