Split Mvc.Core
This is the first step is some more refactorings to come in the future with the goal of making MVC less monolythic. This makes the core of MVC more reusable and more in line with the design of other vNext platform components. With this change, Mvc.Core contains just the minimal guts needed to build a working app. - Action Discovery - Action Invoker - Filters - ObjectResult - Model Metadata - Model Binding - Formatters - Validation System And yes, we are aware of the irony of 'minimal MVC' not including the view system. The idea is that this is the kernel of an MVC app, and anything real is layered on top. The most noticable impact of this change is that MvcOptions has been blown apart into more managable chunks. See the various ConfigureMvc*** methods. The new Mvc.Extensions package is a placeholder while we evaluate and tune the new definitions. Expect more changes as features are move to their own packages, and in some case their own repositories. For now there is no experience to bootstrap an Mvc.Core app. That's coming next.
This commit is contained in:
parent
03571cc27b
commit
a679e87a9b
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.22822.1
|
||||
VisualStudioVersion = 14.0.22808.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{DAAE4C74-D06F-4874-A166-33305D2643CE}"
|
||||
EndProject
|
||||
|
|
@ -70,6 +70,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.ApiExp
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.ApiExplorer.Test", "test\Microsoft.AspNet.Mvc.ApiExplorer.Test\Microsoft.AspNet.Mvc.ApiExplorer.Test.xproj", "{4C2AD8AB-8AC0-46C4-80C6-C5577C7255F6}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Extensions", "src\Microsoft.AspNet.Mvc.Extensions\Microsoft.AspNet.Mvc.Extensions.xproj", "{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Extensions.Test", "test\Microsoft.AspNet.Mvc.Extensions.Test\Microsoft.AspNet.Mvc.Extensions.Test.xproj", "{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -391,6 +395,30 @@ Global
|
|||
{4C2AD8AB-8AC0-46C4-80C6-C5577C7255F6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{4C2AD8AB-8AC0-46C4-80C6-C5577C7255F6}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{4C2AD8AB-8AC0-46C4-80C6-C5577C7255F6}.Release|x86.Build.0 = Release|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Release|x86.Build.0 = Release|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -424,5 +452,7 @@ Global
|
|||
{DA000953-7532-4DF5-8DB9-8143DF98D999} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
{A2B72833-5D70-4C42-AE85-E0319926FB8A} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{4C2AD8AB-8AC0-46C4-80C6-C5577C7255F6} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
30
Mvc.sln
30
Mvc.sln
|
|
@ -170,6 +170,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Abstra
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LocalizationWebSite", "test\WebSites\LocalizationWebSite\LocalizationWebSite.xproj", "{FCFE6024-2720-49B4-8257-9DBC6114F0F1}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Extensions", "src\Microsoft.AspNet.Mvc.Extensions\Microsoft.AspNet.Mvc.Extensions.xproj", "{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Extensions.Test", "test\Microsoft.AspNet.Mvc.Extensions.Test\Microsoft.AspNet.Mvc.Extensions.Test.xproj", "{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -1024,6 +1028,30 @@ Global
|
|||
{FCFE6024-2720-49B4-8257-9DBC6114F0F1}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{FCFE6024-2720-49B4-8257-9DBC6114F0F1}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{FCFE6024-2720-49B4-8257-9DBC6114F0F1}.Release|x86.Build.0 = Release|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94}.Release|x86.Build.0 = Release|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -1107,5 +1135,7 @@ Global
|
|||
{4C2AD8AB-8AC0-46C4-80C6-C5577C7255F6} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
{DA000953-7532-4DF5-8DB9-8143DF98D999} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
{FCFE6024-2720-49B4-8257-9DBC6114F0F1} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
|
||||
{B2CA101A-87E6-4DD2-9BB2-28DA68EF1A94} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{5DF6EFA5-865E-450B-BF83-DE9CE88EB77C} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
|
|||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Will be null if the action returns no response, or if the response type is unclear. Use
|
||||
/// <see cref="ProducesAttribute"/> on an action method to specify a response type.
|
||||
/// <c>ProducesAttribute</c> on an action method to specify a response type.
|
||||
/// </remarks>
|
||||
public Type ResponseType { get; set; }
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
|
|||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Will be empty if the action returns no response, or if the response type is unclear. Use
|
||||
/// <see cref="ProducesAttribute"/> on an action method to specify a response type.
|
||||
/// <c>ProducesAttribute</c> on an action method to specify a response type.
|
||||
/// </remarks>
|
||||
public IList<ApiResponseFormat> SupportedResponseFormats { get; private set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using Microsoft.AspNet.Mvc.ApiExplorer;
|
|||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// Controls the visibility and group name for an <see cref="ApiDescription"/>
|
||||
/// Controls the visibility and group name for an <c>ApiDescription</c>
|
||||
/// of the associated controller class or action method.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
|
|
@ -5,8 +5,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Cors.Core;
|
||||
using Microsoft.AspNet.Mvc.ApiExplorer;
|
||||
using Microsoft.AspNet.Mvc.Filters;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
|
|
@ -18,15 +16,11 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
|||
{
|
||||
public class DefaultApplicationModelProvider : IApplicationModelProvider
|
||||
{
|
||||
private readonly AuthorizationOptions _authorizationOptions;
|
||||
private readonly ICollection<IFilter> _globalFilters;
|
||||
|
||||
public DefaultApplicationModelProvider(
|
||||
IOptions<MvcOptions> mvcOptionsAccessor,
|
||||
IOptions<AuthorizationOptions> authorizationOptionsAccessor)
|
||||
public DefaultApplicationModelProvider(IOptions<MvcOptions> mvcOptionsAccessor)
|
||||
{
|
||||
_globalFilters = mvcOptionsAccessor.Options.Filters;
|
||||
_authorizationOptions = authorizationOptionsAccessor.Options;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -182,24 +176,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
|||
AddRange(controllerModel.Filters, attributes.OfType<IFilter>());
|
||||
AddRange(controllerModel.RouteConstraints, attributes.OfType<IRouteConstraintProvider>());
|
||||
|
||||
var enableCors = attributes.OfType<IEnableCorsAttribute>().SingleOrDefault();
|
||||
if (enableCors != null)
|
||||
{
|
||||
controllerModel.Filters.Add(new CorsAuthorizationFilterFactory(enableCors.PolicyName));
|
||||
}
|
||||
|
||||
var disableCors = attributes.OfType<IDisableCorsAttribute>().SingleOrDefault();
|
||||
if (disableCors != null)
|
||||
{
|
||||
controllerModel.Filters.Add(new DisableCorsAuthorizationFilter());
|
||||
}
|
||||
|
||||
var policy = AuthorizationPolicy.Combine(_authorizationOptions, attributes.OfType<AuthorizeAttribute>());
|
||||
if (policy != null)
|
||||
{
|
||||
controllerModel.Filters.Add(new AuthorizeFilter(policy));
|
||||
}
|
||||
|
||||
var apiVisibility = attributes.OfType<IApiDescriptionVisibilityProvider>().FirstOrDefault();
|
||||
if (apiVisibility != null)
|
||||
{
|
||||
|
|
@ -529,24 +505,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
|||
AddRange(actionModel.ActionConstraints, attributes.OfType<IActionConstraintMetadata>());
|
||||
AddRange(actionModel.Filters, attributes.OfType<IFilter>());
|
||||
|
||||
var enableCors = attributes.OfType<IEnableCorsAttribute>().SingleOrDefault();
|
||||
if (enableCors != null)
|
||||
{
|
||||
actionModel.Filters.Add(new CorsAuthorizationFilterFactory(enableCors.PolicyName));
|
||||
}
|
||||
|
||||
var disableCors = attributes.OfType<IDisableCorsAttribute>().SingleOrDefault();
|
||||
if (disableCors != null)
|
||||
{
|
||||
actionModel.Filters.Add(new DisableCorsAuthorizationFilter());
|
||||
}
|
||||
|
||||
var policy = AuthorizationPolicy.Combine(_authorizationOptions, attributes.OfType<AuthorizeAttribute>());
|
||||
if (policy != null)
|
||||
{
|
||||
actionModel.Filters.Add(new AuthorizeFilter(policy));
|
||||
}
|
||||
|
||||
var actionName = attributes.OfType<ActionNameAttribute>().FirstOrDefault();
|
||||
if (actionName?.Name != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -69,4 +69,4 @@ namespace Microsoft.AspNet.Mvc.Core
|
|||
return context.Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
"Microsoft.AspNet.Mvc.Abstractions",
|
||||
"Microsoft.AspNet.Mvc.ApiExplorer",
|
||||
"Microsoft.AspNet.Mvc.Core",
|
||||
"Microsoft.AspNet.Mvc.Extensions",
|
||||
"Microsoft.AspNet.Mvc.Razor",
|
||||
"Microsoft.AspNet.Mvc.Razor.Host",
|
||||
"Microsoft.AspNet.Mvc.TagHelpers",
|
||||
|
|
|
|||
|
|
@ -19,20 +19,24 @@ namespace Microsoft.AspNet.Mvc
|
|||
public class DefaultControllerFactory : IControllerFactory
|
||||
{
|
||||
private readonly IControllerActivator _controllerActivator;
|
||||
private readonly ConcurrentDictionary<Type, PropertyActivator<ActionContext>[]> _activateActions;
|
||||
private readonly Func<Type, PropertyActivator<ActionContext>[]> _getPropertiesToActivate;
|
||||
private readonly IControllerPropertyActivator[] _propertyActivators;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="DefaultControllerFactory"/>.
|
||||
/// </summary>
|
||||
/// <param name="controllerActivator"><see cref="IControllerActivator"/> used to create controller
|
||||
/// instances.</param>
|
||||
public DefaultControllerFactory(IControllerActivator controllerActivator)
|
||||
/// <param name="controllerActivator">
|
||||
/// <see cref="IControllerActivator"/> used to create controller instances.
|
||||
/// </param>
|
||||
/// <param name="propertyActivators">
|
||||
/// A set of <see cref="IControllerPropertyActivator"/> instances used to initialize controller
|
||||
/// properties.
|
||||
/// </param>
|
||||
public DefaultControllerFactory(
|
||||
IControllerActivator controllerActivator,
|
||||
IEnumerable<IControllerPropertyActivator> propertyActivators)
|
||||
{
|
||||
_controllerActivator = controllerActivator;
|
||||
|
||||
_activateActions = new ConcurrentDictionary<Type, PropertyActivator<ActionContext>[]>();
|
||||
_getPropertiesToActivate = GetPropertiesToActivate;
|
||||
_propertyActivators = propertyActivators.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -71,7 +75,10 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
|
||||
var controller = _controllerActivator.Create(actionContext, controllerType);
|
||||
ActivateProperties(controller, actionContext);
|
||||
foreach (var propertyActivator in _propertyActivators)
|
||||
{
|
||||
propertyActivator.Activate(actionContext, controller);
|
||||
}
|
||||
|
||||
return controller;
|
||||
}
|
||||
|
|
@ -86,60 +93,5 @@ namespace Microsoft.AspNet.Mvc
|
|||
disposableController.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activates the specified controller using the specified action context.
|
||||
/// </summary>
|
||||
/// <param name="controller">The controller to activate.</param>
|
||||
/// <param name="context">The context of the executing action.</param>
|
||||
protected virtual void ActivateProperties([NotNull] object controller, [NotNull] ActionContext context)
|
||||
{
|
||||
var controllerType = controller.GetType();
|
||||
var propertiesToActivate = _activateActions.GetOrAdd(
|
||||
controllerType,
|
||||
_getPropertiesToActivate);
|
||||
|
||||
for (var i = 0; i < propertiesToActivate.Length; i++)
|
||||
{
|
||||
var activateInfo = propertiesToActivate[i];
|
||||
activateInfo.Activate(controller, context);
|
||||
}
|
||||
}
|
||||
|
||||
private PropertyActivator<ActionContext>[] GetPropertiesToActivate(Type type)
|
||||
{
|
||||
IEnumerable<PropertyActivator<ActionContext>> activators;
|
||||
activators = PropertyActivator<ActionContext>.GetPropertiesToActivate(
|
||||
type,
|
||||
typeof(ActionContextAttribute),
|
||||
p => new PropertyActivator<ActionContext>(p, c => c));
|
||||
|
||||
activators = activators.Concat(PropertyActivator<ActionContext>.GetPropertiesToActivate(
|
||||
type,
|
||||
typeof(ActionBindingContextAttribute),
|
||||
p => new PropertyActivator<ActionContext>(p, GetActionBindingContext)));
|
||||
|
||||
activators = activators.Concat(PropertyActivator<ActionContext>.GetPropertiesToActivate(
|
||||
type,
|
||||
typeof(ViewDataDictionaryAttribute),
|
||||
p => new PropertyActivator<ActionContext>(p, GetViewDataDictionary)));
|
||||
|
||||
return activators.ToArray();
|
||||
}
|
||||
|
||||
private static ActionBindingContext GetActionBindingContext(ActionContext context)
|
||||
{
|
||||
var serviceProvider = context.HttpContext.RequestServices;
|
||||
var accessor = serviceProvider.GetRequiredService<IScopedInstance<ActionBindingContext>>();
|
||||
return accessor.Value;
|
||||
}
|
||||
|
||||
private static ViewDataDictionary GetViewDataDictionary(ActionContext context)
|
||||
{
|
||||
var serviceProvider = context.HttpContext.RequestServices;
|
||||
return new ViewDataDictionary(
|
||||
serviceProvider.GetRequiredService<IModelMetadataProvider>(),
|
||||
context.ModelState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public class DefaultControllerPropertyActivator : IControllerPropertyActivator
|
||||
{
|
||||
private readonly ConcurrentDictionary<Type, PropertyActivator<ActionContext>[]> _activateActions;
|
||||
private readonly Func<Type, PropertyActivator<ActionContext>[]> _getPropertiesToActivate;
|
||||
|
||||
public DefaultControllerPropertyActivator()
|
||||
{
|
||||
_activateActions = new ConcurrentDictionary<Type, PropertyActivator<ActionContext>[]>();
|
||||
_getPropertiesToActivate = GetPropertiesToActivate;
|
||||
}
|
||||
|
||||
public void Activate(ActionContext actionContext, object controller)
|
||||
{
|
||||
var controllerType = controller.GetType();
|
||||
var propertiesToActivate = _activateActions.GetOrAdd(
|
||||
controllerType,
|
||||
_getPropertiesToActivate);
|
||||
|
||||
for (var i = 0; i < propertiesToActivate.Length; i++)
|
||||
{
|
||||
var activateInfo = propertiesToActivate[i];
|
||||
activateInfo.Activate(controller, actionContext);
|
||||
}
|
||||
}
|
||||
|
||||
private PropertyActivator<ActionContext>[] GetPropertiesToActivate(Type type)
|
||||
{
|
||||
IEnumerable<PropertyActivator<ActionContext>> activators;
|
||||
activators = PropertyActivator<ActionContext>.GetPropertiesToActivate(
|
||||
type,
|
||||
typeof(ActionContextAttribute),
|
||||
p => new PropertyActivator<ActionContext>(p, c => c));
|
||||
|
||||
activators = activators.Concat(PropertyActivator<ActionContext>.GetPropertiesToActivate(
|
||||
type,
|
||||
typeof(ActionBindingContextAttribute),
|
||||
p => new PropertyActivator<ActionContext>(p, GetActionBindingContext)));
|
||||
|
||||
return activators.ToArray();
|
||||
}
|
||||
|
||||
private static ActionBindingContext GetActionBindingContext(ActionContext context)
|
||||
{
|
||||
var serviceProvider = context.HttpContext.RequestServices;
|
||||
var accessor = serviceProvider.GetRequiredService<IScopedInstance<ActionBindingContext>>();
|
||||
return accessor.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,8 +15,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
/// </summary>
|
||||
public class DefaultControllerTypeProvider : IControllerTypeProvider
|
||||
{
|
||||
private const string ControllerTypeName = nameof(Controller);
|
||||
private static readonly TypeInfo ControllerTypeInfo = typeof(Controller).GetTypeInfo();
|
||||
private const string ControllerTypeName = "Controller";
|
||||
private static readonly TypeInfo ObjectTypeInfo = typeof(object).GetTypeInfo();
|
||||
private readonly IAssemblyProvider _assemblyProvider;
|
||||
|
||||
|
|
@ -83,14 +82,6 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
private bool DerivesFromController(TypeInfo typeInfo, ISet<Assembly> candidateAssemblies)
|
||||
{
|
||||
// A type is a controller if it derives from a type that is either named "Controller" or has the suffix
|
||||
// "Controller". We'll optimize the most common case of types deriving from the Mvc Controller type and
|
||||
// walk up the object graph if that's not the case.
|
||||
if (ControllerTypeInfo.IsAssignableFrom(typeInfo))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
while (typeInfo != ObjectTypeInfo)
|
||||
{
|
||||
var baseTypeInfo = typeInfo.BaseType.GetTypeInfo();
|
||||
|
|
@ -105,6 +96,12 @@ namespace Microsoft.AspNet.Mvc
|
|||
return true;
|
||||
}
|
||||
|
||||
// c). The base type is called 'Controller.
|
||||
if (string.Equals(baseTypeInfo.Name, ControllerTypeName, StringComparison.Ordinal))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
typeInfo = baseTypeInfo;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
public static readonly int DefaultFrameworkSortOrder = -1000;
|
||||
|
||||
/// <summary>
|
||||
/// The default order for <see cref="CorsAuthorizationFilter"/>, <see cref="CorsAuthorizationFilterFactory"/>
|
||||
/// and <see cref="DisableCorsAuthorizationFilter"/>.
|
||||
/// The default order for <c>CorsAuthorizationFilter</c>, <c>CorsAuthorizationFilterFactory</c>
|
||||
/// and <c>DisableCorsAuthorizationFilter</c>
|
||||
/// </summary>
|
||||
public static readonly int DefaultCorsSortOrder = int.MaxValue - 100;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
public interface IAssemblyProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the sequence of candidate <see cref="Assembly"/>ies that the application
|
||||
/// Gets the sequence of candidate <see cref="Assembly"/> instances that the application
|
||||
/// uses for discovery of Mvc specific types.
|
||||
/// </summary>
|
||||
IEnumerable<Assembly> CandidateAssemblies { get; }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public interface IControllerPropertyActivator
|
||||
{
|
||||
void Activate(ActionContext actionContext, object controller);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +1,12 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Mvc.ApplicationModels;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Core.Internal;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding.Metadata;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -20,57 +15,21 @@ namespace Microsoft.AspNet.Mvc
|
|||
/// </summary>
|
||||
public class MvcOptions
|
||||
{
|
||||
private AntiForgeryOptions _antiForgeryOptions = new AntiForgeryOptions();
|
||||
private int _maxModelStateErrors = ModelStateDictionary.DefaultMaxAllowedErrors;
|
||||
|
||||
public MvcOptions()
|
||||
{
|
||||
Conventions = new List<IApplicationModelConvention>();
|
||||
ModelBinders = new List<IModelBinder>();
|
||||
ViewEngines = new List<ViewEngineDescriptor>();
|
||||
ValueProviderFactories = new List<IValueProviderFactory>();
|
||||
OutputFormatters = new List<IOutputFormatter>();
|
||||
InputFormatters = new List<IInputFormatter>();
|
||||
Filters = new List<IFilter>();
|
||||
FormatterMappings = new FormatterMappings();
|
||||
ValidationExcludeFilters = new List<IExcludeTypeValidationFilter>();
|
||||
InputFormatters = new List<IInputFormatter>();
|
||||
OutputFormatters = new List<IOutputFormatter>();
|
||||
ModelBinders = new List<IModelBinder>();
|
||||
ModelMetadataDetailsProviders = new List<IMetadataDetailsProvider>();
|
||||
ModelValidatorProviders = new List<IModelValidatorProvider>();
|
||||
ClientModelValidatorProviders = new List<IClientModelValidatorProvider>();
|
||||
CacheProfiles = new Dictionary<string, CacheProfile>(StringComparer.OrdinalIgnoreCase);
|
||||
HtmlHelperOptions = new HtmlHelperOptions();
|
||||
SerializerSettings = SerializerSettingsProvider.CreateSerializerSettings();
|
||||
ValidationExcludeFilters = new List<IExcludeTypeValidationFilter>();
|
||||
ValueProviderFactories = new List<IValueProviderFactory>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides programmatic configuration for the anti-forgery token system.
|
||||
/// </summary>
|
||||
public AntiForgeryOptions AntiForgeryOptions
|
||||
{
|
||||
get
|
||||
{
|
||||
return _antiForgeryOptions;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value),
|
||||
Resources.FormatPropertyOfTypeCannotBeNull(nameof(AntiForgeryOptions),
|
||||
typeof(MvcOptions)));
|
||||
}
|
||||
|
||||
_antiForgeryOptions = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to specify mapping between the URL Format and corresponding
|
||||
/// <see cref="Net.Http.Headers.MediaTypeHeaderValue"/>.
|
||||
/// </summary>
|
||||
public FormatterMappings FormatterMappings { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IFilter"/> which are used to construct filters that
|
||||
/// apply to all actions.
|
||||
|
|
@ -88,15 +47,9 @@ namespace Microsoft.AspNet.Mvc
|
|||
public IList<IInputFormatter> InputFormatters { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="JsonSerializerSettings"/> that are used by this application.
|
||||
/// Gets a list of <see cref="IModelBinder"/>s used by this application.
|
||||
/// </summary>
|
||||
public JsonSerializerSettings SerializerSettings { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IExcludeTypeValidationFilter"/>s that are used by this application.
|
||||
/// </summary>
|
||||
public IList<IExcludeTypeValidationFilter> ValidationExcludeFilters { get; }
|
||||
= new List<IExcludeTypeValidationFilter>();
|
||||
public IList<IModelBinder> ModelBinders { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum number of validation errors that are allowed by this application before further
|
||||
|
|
@ -116,27 +69,11 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IModelBinder"/>s used by this application.
|
||||
/// </summary>
|
||||
public IList<IModelBinder> ModelBinders { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IModelValidatorProvider"/>s used by this application.
|
||||
/// </summary>
|
||||
public IList<IModelValidatorProvider> ModelValidatorProviders { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IClientModelValidatorProvider"/> instances.
|
||||
/// </summary>
|
||||
public IList<IClientModelValidatorProvider> ClientModelValidatorProviders { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of descriptors that represent <see cref="Rendering.IViewEngine"/> used
|
||||
/// by this application.
|
||||
/// </summary>
|
||||
public IList<ViewEngineDescriptor> ViewEngines { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IValueProviderFactory"/> used by this application.
|
||||
/// </summary>
|
||||
|
|
@ -154,12 +91,6 @@ namespace Microsoft.AspNet.Mvc
|
|||
/// </summary>
|
||||
public bool RespectBrowserAcceptHeader { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Dictionary of CacheProfile Names, <see cref="CacheProfile"/> which are pre-defined settings for
|
||||
/// <see cref="ResponseCacheFilter"/>.
|
||||
/// </summary>
|
||||
public IDictionary<string, CacheProfile> CacheProfiles { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="IMetadataDetailsProvider"/> instances that will be used to
|
||||
/// create <see cref="ModelMetadata"/> instances.
|
||||
|
|
@ -176,8 +107,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
public IList<IMetadataDetailsProvider> ModelMetadataDetailsProviders { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets programmatic configuration for the HTML helpers and <see cref="ViewContext"/>.
|
||||
/// Gets a list of <see cref="IExcludeTypeValidationFilter"/>s that are used by this application.
|
||||
/// </summary>
|
||||
public HtmlHelperOptions HtmlHelperOptions { get; [param: NotNull] set; }
|
||||
public IList<IExcludeTypeValidationFilter> ValidationExcludeFilters { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,5 @@ using System.Runtime.CompilerServices;
|
|||
[assembly: InternalsVisibleTo("Microsoft.AspNet.Mvc.Core.Test")]
|
||||
[assembly: InternalsVisibleTo("Microsoft.AspNet.Mvc.Razor.Test")]
|
||||
[assembly: InternalsVisibleTo("Microsoft.AspNet.Mvc.TagHelpers.Test")]
|
||||
[assembly: InternalsVisibleTo("Microsoft.AspNet.Mvc.Xml.Test")]
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
[assembly: AssemblyMetadata("Serviceable", "True")]
|
||||
|
|
|
|||
|
|
@ -5,42 +5,22 @@
|
|||
"warningsAsErrors": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Authentication": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authorization": "1.0.0-*",
|
||||
"Microsoft.AspNet.Cors.Core": "1.0.0-*",
|
||||
"Microsoft.AspNet.DataProtection": "1.0.0-*",
|
||||
"Microsoft.AspNet.Diagnostics.Abstractions": "1.0.0-*",
|
||||
"Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*",
|
||||
"Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*",
|
||||
"Microsoft.AspNet.Http.Extensions": "1.0.0-*",
|
||||
"Microsoft.AspNet.JsonPatch": "1.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.Abstractions": "6.0.0-*",
|
||||
"Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" },
|
||||
"Microsoft.AspNet.Routing": "1.0.0-*",
|
||||
"Microsoft.Framework.BufferEntryCollection.Sources": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.AspNet.WebUtilities": "1.0.0-*",
|
||||
"Microsoft.Framework.ClosedGenericMatcher.Sources": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Framework.CopyOnWriteDictionary.Sources": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Framework.Logging.Abstractions": "1.0.0-*",
|
||||
"Microsoft.Framework.Notification": "1.0.0-*",
|
||||
"Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Framework.PropertyActivator.Sources": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Framework.Runtime.Abstractions": "1.0.0-*",
|
||||
"Microsoft.Framework.WebEncoders": "1.0.0-*"
|
||||
"Newtonsoft.Json": "6.0.6"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": {
|
||||
"frameworkAssemblies": {
|
||||
"System.ComponentModel.DataAnnotations": "",
|
||||
"System.Runtime.Serialization": ""
|
||||
}
|
||||
},
|
||||
"dnxcore50": {
|
||||
"dependencies": {
|
||||
"System.ComponentModel.Annotations": "4.0.10-beta-*",
|
||||
"System.Runtime.Serialization.Primitives": "4.0.10-beta-*",
|
||||
"Microsoft.CSharp": "4.0.0-beta-*"
|
||||
}
|
||||
}
|
||||
"dnx451": { },
|
||||
"dnxcore50": { }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ namespace Microsoft.AspNet.Mvc
|
|||
public AntiForgery([NotNull] IClaimUidExtractor claimUidExtractor,
|
||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||
[NotNull] IAntiForgeryAdditionalDataProvider additionalDataProvider,
|
||||
[NotNull] IOptions<MvcOptions> mvcOptions,
|
||||
[NotNull] IOptions<AntiForgeryOptions> antiforgeryOptions,
|
||||
[NotNull] IHtmlEncoder htmlEncoder,
|
||||
[NotNull] IOptions<DataProtectionOptions> dataProtectionOptions)
|
||||
{
|
||||
var config = mvcOptions.Options.AntiForgeryOptions;
|
||||
var config = antiforgeryOptions.Options;
|
||||
var applicationId = dataProtectionOptions.Options.ApplicationDiscriminator ?? string.Empty;
|
||||
config.CookieName = config.CookieName ?? ComputeCookieName(applicationId);
|
||||
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Diagnostics;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.AspNet.DataProtection;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
using Microsoft.AspNet.WebUtilities;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -6,7 +6,7 @@ using System.Diagnostics;
|
|||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.WebEncoders;
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Mvc.ApplicationModels;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public class AuthorizationApplicationModelProvider : IApplicationModelProvider
|
||||
{
|
||||
private readonly AuthorizationOptions _authorizationOptions;
|
||||
|
||||
public AuthorizationApplicationModelProvider(IOptions<AuthorizationOptions> authorizationOptionsAccessor)
|
||||
{
|
||||
_authorizationOptions = authorizationOptionsAccessor.Options;
|
||||
}
|
||||
|
||||
public int Order { get { return DefaultOrder.DefaultFrameworkSortOrder + 10; } }
|
||||
|
||||
public void OnProvidersExecuted([NotNull]ApplicationModelProviderContext context)
|
||||
{
|
||||
// Intentionally empty.
|
||||
}
|
||||
|
||||
public void OnProvidersExecuting([NotNull]ApplicationModelProviderContext context)
|
||||
{
|
||||
AuthorizationPolicy policy;
|
||||
|
||||
foreach (var controllerModel in context.Result.Controllers)
|
||||
{
|
||||
policy = AuthorizationPolicy.Combine(
|
||||
_authorizationOptions,
|
||||
controllerModel.Attributes.OfType<AuthorizeAttribute>());
|
||||
if (policy != null)
|
||||
{
|
||||
controllerModel.Filters.Add(new AuthorizeFilter(policy));
|
||||
}
|
||||
|
||||
foreach (var actionModel in controllerModel.Actions)
|
||||
{
|
||||
policy = AuthorizationPolicy.Combine(
|
||||
_authorizationOptions,
|
||||
actionModel.Attributes.OfType<AuthorizeAttribute>());
|
||||
if (policy != null)
|
||||
{
|
||||
actionModel.Filters.Add(new AuthorizeFilter(policy));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ using System.Security.Claims;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Cors.Core;
|
||||
using Microsoft.AspNet.Mvc.ApplicationModels;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public class CorsApplicationModelProvider : IApplicationModelProvider
|
||||
{
|
||||
public int Order { get { return DefaultOrder.DefaultFrameworkSortOrder + 10; } }
|
||||
|
||||
public void OnProvidersExecuted([NotNull]ApplicationModelProviderContext context)
|
||||
{
|
||||
// Intentionally empty.
|
||||
}
|
||||
|
||||
public void OnProvidersExecuting([NotNull]ApplicationModelProviderContext context)
|
||||
{
|
||||
IEnableCorsAttribute enableCors;
|
||||
IDisableCorsAttribute disableCors;
|
||||
|
||||
foreach (var controllerModel in context.Result.Controllers)
|
||||
{
|
||||
enableCors = controllerModel.Attributes.OfType<IEnableCorsAttribute>().FirstOrDefault();
|
||||
if (enableCors != null)
|
||||
{
|
||||
controllerModel.Filters.Add(new CorsAuthorizationFilterFactory(enableCors.PolicyName));
|
||||
}
|
||||
|
||||
disableCors = controllerModel.Attributes.OfType<IDisableCorsAttribute>().FirstOrDefault();
|
||||
if (disableCors != null)
|
||||
{
|
||||
controllerModel.Filters.Add(new DisableCorsAuthorizationFilter());
|
||||
}
|
||||
|
||||
foreach (var actionModel in controllerModel.Actions)
|
||||
{
|
||||
enableCors = actionModel.Attributes.OfType<IEnableCorsAttribute>().FirstOrDefault();
|
||||
if (enableCors != null)
|
||||
{
|
||||
actionModel.Filters.Add(new CorsAuthorizationFilterFactory(enableCors.PolicyName));
|
||||
}
|
||||
|
||||
disableCors = actionModel.Attributes.OfType<IDisableCorsAttribute>().FirstOrDefault();
|
||||
if (disableCors != null)
|
||||
{
|
||||
actionModel.Filters.Add(new DisableCorsAuthorizationFilter());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
using Microsoft.AspNet.WebUtilities;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
using Microsoft.AspNet.WebUtilities;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
|
@ -9,7 +9,7 @@ using Microsoft.AspNet.FileProviders;
|
|||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
/// </summary>
|
||||
/// <param name="options">The <see cref="IOptions{MvcOptions}"/></param>
|
||||
/// <param name="actionContext">The <see cref="IScopedInstance{ActionContext}"/></param>
|
||||
public FormatFilter(IOptions<MvcOptions> options, IScopedInstance<ActionContext> actionContext)
|
||||
public FormatFilter(IOptions<MvcFormatterMappingOptions> options, IScopedInstance<ActionContext> actionContext)
|
||||
{
|
||||
IsActive = true;
|
||||
Format = GetFormat(actionContext.Value);
|
||||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.ApiExplorer;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
|
@ -88,7 +88,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public IFilter CreateInstance([NotNull] IServiceProvider serviceProvider)
|
||||
{
|
||||
var optionsAccessor = serviceProvider.GetRequiredService<IOptions<MvcOptions>>();
|
||||
var optionsAccessor = serviceProvider.GetRequiredService<IOptions<MvcCacheOptions>>();
|
||||
|
||||
CacheProfile selectedProfile = null;
|
||||
if (CacheProfileName != null)
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Extensions;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Core.Internal;
|
||||
using Microsoft.AspNet.Mvc.Internal;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Newtonsoft.Json;
|
||||
|
|
@ -4,7 +4,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Core.Internal;
|
||||
using Microsoft.AspNet.Mvc.Internal;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue