parent
36c5efd0e2
commit
ed8e5716ea
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.ActionConstraints;
|
||||
using Microsoft.AspNet.Mvc.WebApiCompatShim;
|
||||
using MvcSample.Web.Models;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.ActionConstraints
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an <see cref="IActionConstraintMetadata"/> with or without a corresponding
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.ActionConstraints
|
||||
{
|
||||
/// <summary>
|
||||
/// Context for an action constraint provider.
|
||||
|
|
|
|||
|
|
@ -2,20 +2,19 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.ActionConstraints
|
||||
{
|
||||
/// <summary>
|
||||
/// A default implementation of <see cref="INestedProvider{ActionConstraintProviderContext}"/>.
|
||||
/// A default implementation of <see cref="IActionConstraintProvider"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This provider is able to provide an <see cref="IActionConstraint"/> instance when the
|
||||
/// <see cref="IActionConstraintMetadata"/> implements <see cref="IActionConstraint"/> or
|
||||
/// <see cref="IActionConstraintFactory"/>/
|
||||
/// </remarks>
|
||||
public class DefaultActionConstraintProvider : INestedProvider<ActionConstraintProviderContext>
|
||||
public class DefaultActionConstraintProvider : IActionConstraintProvider
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public int Order
|
||||
|
|
@ -24,14 +23,17 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Invoke([NotNull] ActionConstraintProviderContext context, [NotNull] Action callNext)
|
||||
public void OnProvidersExecuting([NotNull] ActionConstraintProviderContext context)
|
||||
{
|
||||
foreach (var item in context.Results)
|
||||
{
|
||||
ProvideConstraint(item, context.HttpContext.RequestServices);
|
||||
}
|
||||
}
|
||||
|
||||
callNext();
|
||||
/// <inheritdoc />
|
||||
public void OnProvidersExecuted([NotNull] ActionConstraintProviderContext context)
|
||||
{
|
||||
}
|
||||
|
||||
private void ProvideConstraint(ActionConstraintItem item, IServiceProvider services)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.ActionConstraints
|
||||
{
|
||||
/// <summary>
|
||||
/// A factory for <see cref="IActionConstraint"/>.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ActionConstraints
|
||||
{
|
||||
public interface IActionConstraintProvider
|
||||
{
|
||||
int Order { get; }
|
||||
void OnProvidersExecuting([NotNull] ActionConstraintProviderContext context);
|
||||
void OnProvidersExecuted([NotNull] ActionConstraintProviderContext context);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,15 +3,10 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Core
|
||||
{
|
||||
public class ActionDescriptorProviderContext
|
||||
{
|
||||
public ActionDescriptorProviderContext()
|
||||
{
|
||||
Results = new List<ActionDescriptor>();
|
||||
}
|
||||
|
||||
public IList<ActionDescriptor> Results { get; }
|
||||
public IList<ActionDescriptor> Results { get; } = new List<ActionDescriptor>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,34 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Core
|
||||
{
|
||||
public class ActionInvokerFactory : IActionInvokerFactory
|
||||
{
|
||||
private readonly INestedProviderManager<ActionInvokerProviderContext> _actionInvokerProvider;
|
||||
private readonly IActionInvokerProvider[] _actionInvokerProviders;
|
||||
|
||||
public ActionInvokerFactory(INestedProviderManager<ActionInvokerProviderContext> actionInvokerProvider)
|
||||
public ActionInvokerFactory(IEnumerable<IActionInvokerProvider> actionInvokerProviders)
|
||||
{
|
||||
_actionInvokerProvider = actionInvokerProvider;
|
||||
_actionInvokerProviders = actionInvokerProviders.OrderBy(item => item.Order).ToArray();
|
||||
}
|
||||
|
||||
public IActionInvoker CreateInvoker(ActionContext actionContext)
|
||||
{
|
||||
var context = new ActionInvokerProviderContext(actionContext);
|
||||
_actionInvokerProvider.Invoke(context);
|
||||
|
||||
foreach (var provider in _actionInvokerProviders)
|
||||
{
|
||||
provider.OnProvidersExecuting(context);
|
||||
}
|
||||
|
||||
for (var i = _actionInvokerProviders.Length - 1; i >= 0; i--)
|
||||
{
|
||||
_actionInvokerProviders[i].OnProvidersExecuted(context);
|
||||
}
|
||||
|
||||
return context.Result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@
|
|||
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Core
|
||||
{
|
||||
public class ActionInvokerProviderContext
|
||||
{
|
||||
public ActionInvokerProviderContext([NotNull]ActionContext actionContext)
|
||||
public ActionInvokerProviderContext([NotNull] ActionContext actionContext)
|
||||
{
|
||||
ActionContext = actionContext;
|
||||
}
|
||||
|
||||
public ActionContext ActionContext { get; private set; }
|
||||
public ActionContext ActionContext { get; }
|
||||
|
||||
public IActionInvoker Result { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. 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.Filters;
|
||||
|
|
@ -10,7 +9,7 @@ using Microsoft.Framework.Internal;
|
|||
using Microsoft.Framework.Logging;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Core
|
||||
{
|
||||
public class ControllerActionDescriptorProvider : IActionDescriptorProvider
|
||||
{
|
||||
|
|
@ -38,17 +37,21 @@ namespace Microsoft.AspNet.Mvc
|
|||
get { return DefaultOrder.DefaultFrameworkSortOrder; }
|
||||
}
|
||||
|
||||
public void Invoke(ActionDescriptorProviderContext context, Action callNext)
|
||||
/// <inheritdoc />
|
||||
public void OnProvidersExecuting ([NotNull] ActionDescriptorProviderContext context)
|
||||
{
|
||||
foreach (var descriptor in GetDescriptors())
|
||||
{
|
||||
context.Results.Add(descriptor);
|
||||
}
|
||||
|
||||
callNext();
|
||||
}
|
||||
|
||||
public IEnumerable<ControllerActionDescriptor> GetDescriptors()
|
||||
/// <inheritdoc />
|
||||
public void OnProvidersExecuted([NotNull] ActionDescriptorProviderContext context)
|
||||
{
|
||||
}
|
||||
|
||||
internal protected IEnumerable<ControllerActionDescriptor> GetDescriptors()
|
||||
{
|
||||
var applicationModel = BuildModel();
|
||||
ApplicationModelConventions.ApplyConventions(applicationModel, _conventions);
|
||||
|
|
@ -62,7 +65,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
return ControllerActionDescriptorBuilder.Build(applicationModel);
|
||||
}
|
||||
|
||||
public ApplicationModel BuildModel()
|
||||
internal protected ApplicationModel BuildModel()
|
||||
{
|
||||
var applicationModel = new ApplicationModel();
|
||||
foreach (var filter in _globalFilters)
|
||||
|
|
|
|||
|
|
@ -5,12 +5,11 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Core
|
||||
{
|
||||
public class ControllerActionInvoker : FilterActionInvoker
|
||||
{
|
||||
|
|
@ -20,7 +19,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public ControllerActionInvoker(
|
||||
[NotNull] ActionContext actionContext,
|
||||
[NotNull] INestedProviderManager<FilterProviderContext> filterProvider,
|
||||
[NotNull] IReadOnlyList<IFilterProvider> filterProviders,
|
||||
[NotNull] IControllerFactory controllerFactory,
|
||||
[NotNull] ControllerActionDescriptor descriptor,
|
||||
[NotNull] IInputFormattersProvider inputFormatterProvider,
|
||||
|
|
@ -31,7 +30,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
[NotNull] IScopedInstance<ActionBindingContext> actionBindingContextAccessor)
|
||||
: base(
|
||||
actionContext,
|
||||
filterProvider,
|
||||
filterProviders,
|
||||
inputFormatterProvider,
|
||||
modelBinderProvider,
|
||||
modelValidatorProviderProvider,
|
||||
|
|
|
|||
|
|
@ -2,16 +2,19 @@
|
|||
// 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 System.Linq;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Core
|
||||
{
|
||||
public class ControllerActionInvokerProvider : IActionInvokerProvider
|
||||
{
|
||||
private readonly IControllerActionArgumentBinder _argumentBinder;
|
||||
private readonly IControllerFactory _controllerFactory;
|
||||
private readonly INestedProviderManager<FilterProviderContext> _filterProvider;
|
||||
private readonly IFilterProvider[] _filterProviders;
|
||||
private readonly IInputFormattersProvider _inputFormattersProvider;
|
||||
private readonly IModelBinderProvider _modelBinderProvider;
|
||||
private readonly IModelValidatorProviderProvider _modelValidationProviderProvider;
|
||||
|
|
@ -21,7 +24,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
public ControllerActionInvokerProvider(
|
||||
IControllerFactory controllerFactory,
|
||||
IInputFormattersProvider inputFormattersProvider,
|
||||
INestedProviderManager<FilterProviderContext> filterProvider,
|
||||
IEnumerable<IFilterProvider> filterProviders,
|
||||
IControllerActionArgumentBinder argumentBinder,
|
||||
IModelBinderProvider modelBinderProvider,
|
||||
IModelValidatorProviderProvider modelValidationProviderProvider,
|
||||
|
|
@ -30,7 +33,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
_controllerFactory = controllerFactory;
|
||||
_inputFormattersProvider = inputFormattersProvider;
|
||||
_filterProvider = filterProvider;
|
||||
_filterProviders = filterProviders.OrderBy(item => item.Order).ToArray();
|
||||
_argumentBinder = argumentBinder;
|
||||
_modelBinderProvider = modelBinderProvider;
|
||||
_modelValidationProviderProvider = modelValidationProviderProvider;
|
||||
|
|
@ -43,7 +46,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
get { return DefaultOrder.DefaultFrameworkSortOrder; }
|
||||
}
|
||||
|
||||
public void Invoke(ActionInvokerProviderContext context, Action callNext)
|
||||
/// <inheritdoc />
|
||||
public void OnProvidersExecuting([NotNull] ActionInvokerProviderContext context)
|
||||
{
|
||||
var actionDescriptor = context.ActionContext.ActionDescriptor as ControllerActionDescriptor;
|
||||
|
||||
|
|
@ -51,7 +55,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
context.Result = new ControllerActionInvoker(
|
||||
context.ActionContext,
|
||||
_filterProvider,
|
||||
_filterProviders,
|
||||
_controllerFactory,
|
||||
actionDescriptor,
|
||||
_inputFormattersProvider,
|
||||
|
|
@ -61,8 +65,11 @@ namespace Microsoft.AspNet.Mvc
|
|||
_valueProviderFactoryProvider,
|
||||
_actionBindingContextAccessor);
|
||||
}
|
||||
}
|
||||
|
||||
callNext();
|
||||
/// <inheritdoc />
|
||||
public void OnProvidersExecuted([NotNull] ActionInvokerProviderContext context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.Logging;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Logging;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Default implementation for ActionDescriptors.
|
||||
|
|
@ -47,22 +48,33 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
private ActionDescriptorsCollection GetCollection()
|
||||
{
|
||||
var actionDescriptorProvider =
|
||||
_serviceProvider.GetRequiredService<INestedProviderManager<ActionDescriptorProviderContext>>();
|
||||
var actionDescriptorProviderContext = new ActionDescriptorProviderContext();
|
||||
var providers =
|
||||
_serviceProvider.GetRequiredServices<IActionDescriptorProvider>()
|
||||
.OrderBy(p => p.Order)
|
||||
.ToArray();
|
||||
|
||||
actionDescriptorProvider.Invoke(actionDescriptorProviderContext);
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
|
||||
foreach (var provider in providers)
|
||||
{
|
||||
provider.OnProvidersExecuting(context);
|
||||
}
|
||||
|
||||
for (var i = providers.Length - 1; i >= 0; i--)
|
||||
{
|
||||
providers[i].OnProvidersExecuted(context);
|
||||
}
|
||||
|
||||
if (_logger.IsEnabled(LogLevel.Verbose))
|
||||
{
|
||||
foreach (var actionDescriptor in actionDescriptorProviderContext.Results)
|
||||
foreach (var actionDescriptor in context.Results)
|
||||
{
|
||||
_logger.WriteVerbose(new ActionDescriptorValues(actionDescriptor));
|
||||
}
|
||||
}
|
||||
|
||||
return new ActionDescriptorsCollection(
|
||||
new ReadOnlyCollection<ActionDescriptor>(actionDescriptorProviderContext.Results), 0);
|
||||
new ReadOnlyCollection<ActionDescriptor>(context.Results), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,32 +6,31 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.ActionConstraints;
|
||||
using Microsoft.AspNet.Mvc.Logging;
|
||||
using Microsoft.AspNet.Mvc.Routing;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.Logging;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Core
|
||||
{
|
||||
public class DefaultActionSelector : IActionSelector
|
||||
{
|
||||
private readonly IActionDescriptorsCollectionProvider _actionDescriptorsCollectionProvider;
|
||||
private readonly IActionSelectorDecisionTreeProvider _decisionTreeProvider;
|
||||
private readonly INestedProviderManager<ActionConstraintProviderContext> _actionConstraintProvider;
|
||||
private readonly IActionConstraintProvider[] _actionConstraintProviders;
|
||||
private ILogger _logger;
|
||||
|
||||
public DefaultActionSelector(
|
||||
[NotNull] IActionDescriptorsCollectionProvider actionDescriptorsCollectionProvider,
|
||||
[NotNull] IActionSelectorDecisionTreeProvider decisionTreeProvider,
|
||||
[NotNull] INestedProviderManager<ActionConstraintProviderContext> actionConstraintProvider,
|
||||
[NotNull] ILoggerFactory loggerFactory)
|
||||
IActionDescriptorsCollectionProvider actionDescriptorsCollectionProvider,
|
||||
IActionSelectorDecisionTreeProvider decisionTreeProvider,
|
||||
IEnumerable<IActionConstraintProvider> actionConstraintProviders,
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
_actionDescriptorsCollectionProvider = actionDescriptorsCollectionProvider;
|
||||
_decisionTreeProvider = decisionTreeProvider;
|
||||
_actionConstraintProvider = actionConstraintProvider;
|
||||
_actionConstraintProviders = actionConstraintProviders.OrderBy(item => item.Order).ToArray();
|
||||
_logger = loggerFactory.Create<DefaultActionSelector>();
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +264,15 @@ namespace Microsoft.AspNet.Mvc
|
|||
var items = action.ActionConstraints.Select(c => new ActionConstraintItem(c)).ToList();
|
||||
var context = new ActionConstraintProviderContext(httpContext, action, items);
|
||||
|
||||
_actionConstraintProvider.Invoke(context);
|
||||
foreach (var provider in _actionConstraintProviders)
|
||||
{
|
||||
provider.OnProvidersExecuting(context);
|
||||
}
|
||||
|
||||
for (var i = _actionConstraintProviders.Length - 1; i >= 0; i--)
|
||||
{
|
||||
_actionConstraintProviders[i].OnProvidersExecuted(context);
|
||||
}
|
||||
|
||||
return
|
||||
context.Results
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
"Microsoft.AspNet.Mvc.ModelBinding",
|
||||
"Microsoft.AspNet.Mvc.Razor",
|
||||
"Microsoft.AspNet.Mvc.Razor.Host",
|
||||
"Microsoft.AspNet.Mvc.TagHelpers",
|
||||
};
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Description
|
||||
{
|
||||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc.Description
|
|||
public class ApiDescriptionGroupCollectionProvider : IApiDescriptionGroupCollectionProvider
|
||||
{
|
||||
private readonly IActionDescriptorsCollectionProvider _actionDescriptorCollectionProvider;
|
||||
private readonly INestedProviderManager<ApiDescriptionProviderContext> _apiDescriptionProvider;
|
||||
private readonly IApiDescriptionProvider[] _apiDescriptionProviders;
|
||||
|
||||
private ApiDescriptionGroupCollection _apiDescriptionGroups;
|
||||
|
||||
|
|
@ -20,15 +20,15 @@ namespace Microsoft.AspNet.Mvc.Description
|
|||
/// <param name="actionDescriptorCollectionProvider">
|
||||
/// The <see cref="IActionDescriptorsCollectionProvider"/>.
|
||||
/// </param>
|
||||
/// <param name="apiDescriptionProvider">
|
||||
/// The <see cref="INestedProviderManager{ApiDescriptionProviderContext}"/>.
|
||||
/// <param name="apiDescriptionProviders">
|
||||
/// The <see cref="IEnumerable{IApiDescriptionProvider}}"/>.
|
||||
/// </param>
|
||||
public ApiDescriptionGroupCollectionProvider(
|
||||
IActionDescriptorsCollectionProvider actionDescriptorCollectionProvider,
|
||||
INestedProviderManager<ApiDescriptionProviderContext> apiDescriptionProvider)
|
||||
IEnumerable<IApiDescriptionProvider> apiDescriptionProviders)
|
||||
{
|
||||
_actionDescriptorCollectionProvider = actionDescriptorCollectionProvider;
|
||||
_apiDescriptionProvider = apiDescriptionProvider;
|
||||
_apiDescriptionProviders = apiDescriptionProviders.OrderBy(item => item.Order).ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -49,7 +49,16 @@ namespace Microsoft.AspNet.Mvc.Description
|
|||
private ApiDescriptionGroupCollection GetCollection(ActionDescriptorsCollection actionDescriptors)
|
||||
{
|
||||
var context = new ApiDescriptionProviderContext(actionDescriptors.Items);
|
||||
_apiDescriptionProvider.Invoke(context);
|
||||
|
||||
foreach (var provider in _apiDescriptionProviders)
|
||||
{
|
||||
provider.OnProvidersExecuting(context);
|
||||
}
|
||||
|
||||
for (var i = _apiDescriptionProviders.Length - 1; i >= 0; i--)
|
||||
{
|
||||
_apiDescriptionProviders[i].OnProvidersExecuted(context);
|
||||
}
|
||||
|
||||
var groups = context.Results
|
||||
.GroupBy(d => d.GroupName)
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.AspNet.Routing.Template;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Description
|
||||
{
|
||||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Mvc.Description
|
|||
/// Implements a provider of <see cref="ApiDescription"/> for actions represented
|
||||
/// by <see cref="ControllerActionDescriptor"/>.
|
||||
/// </summary>
|
||||
public class DefaultApiDescriptionProvider : INestedProvider<ApiDescriptionProviderContext>
|
||||
public class DefaultApiDescriptionProvider : IApiDescriptionProvider
|
||||
{
|
||||
private readonly IOutputFormattersProvider _formattersProvider;
|
||||
private readonly IModelMetadataProvider _modelMetadataProvider;
|
||||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Mvc.Description
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Invoke(ApiDescriptionProviderContext context, Action callNext)
|
||||
public void OnProvidersExecuting([NotNull] ApiDescriptionProviderContext context)
|
||||
{
|
||||
foreach (var action in context.Actions.OfType<ControllerActionDescriptor>())
|
||||
{
|
||||
|
|
@ -59,8 +59,10 @@ namespace Microsoft.AspNet.Mvc.Description
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
callNext();
|
||||
public void OnProvidersExecuted([NotNull] ApiDescriptionProviderContext context)
|
||||
{
|
||||
}
|
||||
|
||||
private ApiDescription CreateApiDescription(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Description
|
||||
{
|
||||
public interface IApiDescriptionProvider
|
||||
{
|
||||
int Order { get; }
|
||||
void OnProvidersExecuting([NotNull] ApiDescriptionProviderContext context);
|
||||
void OnProvidersExecuted([NotNull] ApiDescriptionProviderContext context);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,16 +7,15 @@ using System.Diagnostics;
|
|||
using System.Linq;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Core
|
||||
{
|
||||
public abstract class FilterActionInvoker : IActionInvoker
|
||||
{
|
||||
private readonly INestedProviderManager<FilterProviderContext> _filterProvider;
|
||||
private readonly IReadOnlyList<IFilterProvider> _filterProviders;
|
||||
private readonly IInputFormattersProvider _inputFormatterProvider;
|
||||
private readonly IModelBinderProvider _modelBinderProvider;
|
||||
private readonly IModelValidatorProviderProvider _modelValidatorProviderProvider;
|
||||
|
|
@ -41,7 +40,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public FilterActionInvoker(
|
||||
[NotNull] ActionContext actionContext,
|
||||
[NotNull] INestedProviderManager<FilterProviderContext> filterProvider,
|
||||
[NotNull] IReadOnlyList<IFilterProvider> filterProviders,
|
||||
[NotNull] IInputFormattersProvider inputFormatterProvider,
|
||||
[NotNull] IModelBinderProvider modelBinderProvider,
|
||||
[NotNull] IModelValidatorProviderProvider modelValidatorProviderProvider,
|
||||
|
|
@ -50,7 +49,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
ActionContext = actionContext;
|
||||
|
||||
_filterProvider = filterProvider;
|
||||
_filterProviders = filterProviders;
|
||||
_inputFormatterProvider = inputFormatterProvider;
|
||||
_modelBinderProvider = modelBinderProvider;
|
||||
_modelValidatorProviderProvider = modelValidatorProviderProvider;
|
||||
|
|
@ -142,13 +141,21 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
private IFilter[] GetFilters()
|
||||
{
|
||||
var filterProviderContext = new FilterProviderContext(
|
||||
var context = new FilterProviderContext(
|
||||
ActionContext,
|
||||
ActionContext.ActionDescriptor.FilterDescriptors.Select(fd => new FilterItem(fd)).ToList());
|
||||
|
||||
_filterProvider.Invoke(filterProviderContext);
|
||||
foreach (var provider in _filterProviders)
|
||||
{
|
||||
provider.OnProvidersExecuting(context);
|
||||
}
|
||||
|
||||
return filterProviderContext.Results.Select(item => item.Filter).Where(filter => filter != null).ToArray();
|
||||
for (var i = _filterProviders.Count - 1; i >= 0; i--)
|
||||
{
|
||||
_filterProviders[i].OnProvidersExecuted(context);
|
||||
}
|
||||
|
||||
return context.Results.Select(item => item.Filter).Where(filter => filter != null).ToArray();
|
||||
}
|
||||
|
||||
private async Task InvokeAllAuthorizationFiltersAsync()
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Filters
|
||||
{
|
||||
public class DefaultFilterProvider : INestedProvider<FilterProviderContext>
|
||||
public class DefaultFilterProvider : IFilterProvider
|
||||
{
|
||||
public DefaultFilterProvider(IServiceProvider serviceProvider)
|
||||
{
|
||||
|
|
@ -22,7 +22,8 @@ namespace Microsoft.AspNet.Mvc.Filters
|
|||
|
||||
protected IServiceProvider ServiceProvider { get; private set; }
|
||||
|
||||
public virtual void Invoke(FilterProviderContext context, Action callNext)
|
||||
/// <inheritdoc />
|
||||
public void OnProvidersExecuting([NotNull] FilterProviderContext context)
|
||||
{
|
||||
if (context.ActionContext.ActionDescriptor.FilterDescriptors != null)
|
||||
{
|
||||
|
|
@ -31,11 +32,11 @@ namespace Microsoft.AspNet.Mvc.Filters
|
|||
ProvideFilter(context, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (callNext != null)
|
||||
{
|
||||
callNext();
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public void OnProvidersExecuted([NotNull] FilterProviderContext context)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void ProvideFilter(FilterProviderContext context, FilterItem filterItem)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Core
|
||||
{
|
||||
public interface IFilterProvider
|
||||
{
|
||||
int Order { get; }
|
||||
void OnProvidersExecuting([NotNull] FilterProviderContext context);
|
||||
void OnProvidersExecuted([NotNull] FilterProviderContext context);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,14 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Core
|
||||
{
|
||||
public interface IActionDescriptorProvider : INestedProvider<ActionDescriptorProviderContext>
|
||||
public interface IActionDescriptorProvider
|
||||
{
|
||||
int Order { get; }
|
||||
void OnProvidersExecuting([NotNull] ActionDescriptorProviderContext context);
|
||||
void OnProvidersExecuted([NotNull] ActionDescriptorProviderContext context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Core
|
||||
{
|
||||
public interface IActionInvokerProvider : INestedProvider<ActionInvokerProviderContext>
|
||||
public interface IActionInvokerProvider
|
||||
{
|
||||
int Order { get; }
|
||||
void OnProvidersExecuting([NotNull] ActionInvokerProviderContext context);
|
||||
void OnProvidersExecuted([NotNull] ActionInvokerProviderContext context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +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.ActionConstraints;
|
||||
using Microsoft.Framework.Logging;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Logging
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using System.Text;
|
|||
namespace Microsoft.AspNet.Mvc.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the state of <see cref="DefaultActionSelector.SelectAsync(AspNet.Routing.RouteContext)"/>.
|
||||
/// Represents the state of <see cref="Core.DefaultActionSelector.SelectAsync(AspNet.Routing.RouteContext)"/>.
|
||||
/// </summary>
|
||||
public class DefaultActionSelectorSelectAsyncValues
|
||||
{
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
public static void RemoveTypesOf<TInstance>([NotNull] this IList<ModelBinderDescriptor> descriptors)
|
||||
where TInstance : class, IModelBinder
|
||||
{
|
||||
for (int i = descriptors.Count - 1; i >= 0; i--)
|
||||
for (var i = descriptors.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (descriptors[i].OptionType == typeof(TInstance))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
public static void RemoveTypesOf<TInstance>([NotNull] this IList<OutputFormatterDescriptor> descriptors)
|
||||
where TInstance : class, IOutputFormatter
|
||||
{
|
||||
for (int i = descriptors.Count - 1; i >= 0; i--)
|
||||
for (var i = descriptors.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (descriptors[i].OptionType == typeof(TInstance))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
public static void RemoveTypesOf<TInstance>([NotNull] this IList<ValueProviderFactoryDescriptor> descriptors)
|
||||
where TInstance : class, IValueProviderFactory
|
||||
{
|
||||
for (int i = descriptors.Count - 1; i >= 0; i--)
|
||||
for (var i = descriptors.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (descriptors[i].OptionType == typeof(TInstance))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using Microsoft.AspNet.Mvc.Core;
|
|||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.ViewComponents
|
||||
{
|
||||
public class DefaultViewComponentHelper : IViewComponentHelper, ICanHasViewContext
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,26 +1,37 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.ViewComponents
|
||||
{
|
||||
public class DefaultViewComponentInvokerFactory : IViewComponentInvokerFactory
|
||||
{
|
||||
private readonly INestedProviderManager<ViewComponentInvokerProviderContext> _providerManager;
|
||||
private readonly IViewComponentInvokerProvider[] _providers;
|
||||
|
||||
public DefaultViewComponentInvokerFactory(
|
||||
INestedProviderManager<ViewComponentInvokerProviderContext> providerManager)
|
||||
IEnumerable<IViewComponentInvokerProvider> providers)
|
||||
{
|
||||
_providerManager = providerManager;
|
||||
_providers = providers.OrderBy(item => item.Order).ToArray();
|
||||
}
|
||||
|
||||
public IViewComponentInvoker CreateInstance([NotNull] TypeInfo componentType, object[] args)
|
||||
{
|
||||
var context = new ViewComponentInvokerProviderContext(componentType, args);
|
||||
_providerManager.Invoke(context);
|
||||
|
||||
foreach (var provider in _providers)
|
||||
{
|
||||
provider.OnProvidersExecuting(context);
|
||||
}
|
||||
|
||||
for (var i = _providers.Length - 1; i >= 0; i--)
|
||||
{
|
||||
_providers[i].OnProvidersExecuted(context);
|
||||
}
|
||||
|
||||
return context.Result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.ViewComponents
|
||||
{
|
||||
public class DefaultViewComponentInvokerProvider : IViewComponentInvokerProvider
|
||||
{
|
||||
|
|
@ -28,7 +27,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
get { return DefaultOrder.DefaultFrameworkSortOrder; }
|
||||
}
|
||||
|
||||
public void Invoke([NotNull] ViewComponentInvokerProviderContext context, [NotNull] Action callNext)
|
||||
/// <inheritdoc />
|
||||
public void OnProvidersExecuting([NotNull] ViewComponentInvokerProviderContext context)
|
||||
{
|
||||
context.Result = new DefaultViewComponentInvoker(
|
||||
_serviceProvider,
|
||||
|
|
@ -36,8 +36,11 @@ namespace Microsoft.AspNet.Mvc
|
|||
_viewComponentActivator,
|
||||
context.ComponentType,
|
||||
context.Arguments);
|
||||
}
|
||||
|
||||
callNext();
|
||||
/// <inheritdoc />
|
||||
public void OnProvidersExecuted([NotNull] ViewComponentInvokerProviderContext context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Reflection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.ViewComponents
|
||||
{
|
||||
public interface IViewComponentInvokerFactory
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.ViewComponents
|
||||
{
|
||||
public interface IViewComponentInvokerProvider : INestedProvider<ViewComponentInvokerProviderContext>
|
||||
public interface IViewComponentInvokerProvider
|
||||
{
|
||||
int Order { get; }
|
||||
void OnProvidersExecuting([NotNull] ViewComponentInvokerProviderContext context);
|
||||
void OnProvidersExecuted([NotNull] ViewComponentInvokerProviderContext context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Reflection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.ViewComponents
|
||||
{
|
||||
public class ViewComponentInvokerProviderContext
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Mvc.ActionConstraints;
|
||||
using Microsoft.AspNet.Mvc.ApplicationModels;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Description;
|
||||
using Microsoft.AspNet.Mvc.Filters;
|
||||
using Microsoft.AspNet.Mvc.Internal;
|
||||
|
|
@ -13,10 +15,10 @@ using Microsoft.AspNet.Mvc.Razor.Directives;
|
|||
using Microsoft.AspNet.Mvc.Razor.OptionDescriptors;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Mvc.Routing;
|
||||
using Microsoft.AspNet.Mvc.ViewComponents;
|
||||
using Microsoft.Framework.Cache.Memory;
|
||||
using Microsoft.Framework.ConfigurationModel;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.DependencyInjection.NestedProviders;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
|
|
@ -58,24 +60,16 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
// This provider needs access to the per-request services, but might be used many times for a given
|
||||
// request.
|
||||
yield return describe.Transient<INestedProviderManager<ActionConstraintProviderContext>,
|
||||
NestedProviderManager<ActionConstraintProviderContext>>();
|
||||
yield return describe.Transient<INestedProvider<ActionConstraintProviderContext>,
|
||||
DefaultActionConstraintProvider>();
|
||||
yield return describe.Transient<IActionConstraintProvider, DefaultActionConstraintProvider>();
|
||||
|
||||
yield return describe.Singleton<IActionSelectorDecisionTreeProvider, ActionSelectorDecisionTreeProvider>();
|
||||
yield return describe.Singleton<IActionSelector, DefaultActionSelector>();
|
||||
yield return describe.Transient<IControllerActionArgumentBinder, DefaultControllerActionArgumentBinder>();
|
||||
yield return describe.Transient<IObjectModelValidator, DefaultObjectValidator>();
|
||||
|
||||
yield return describe.Transient<INestedProviderManager<ActionDescriptorProviderContext>,
|
||||
NestedProviderManager<ActionDescriptorProviderContext>>();
|
||||
yield return describe.Transient<INestedProvider<ActionDescriptorProviderContext>,
|
||||
ControllerActionDescriptorProvider>();
|
||||
yield return describe.Transient<IActionDescriptorProvider, ControllerActionDescriptorProvider>();
|
||||
|
||||
yield return describe.Transient<INestedProviderManager<ActionInvokerProviderContext>,
|
||||
NestedProviderManager<ActionInvokerProviderContext>>();
|
||||
yield return describe.Transient<INestedProvider<ActionInvokerProviderContext>,
|
||||
yield return describe.Transient<IActionInvokerProvider,
|
||||
ControllerActionInvokerProvider>();
|
||||
|
||||
yield return describe.Singleton<IActionDescriptorsCollectionProvider,
|
||||
|
|
@ -84,9 +78,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
// The IGlobalFilterProvider is used to build the action descriptors (likely once) and so should
|
||||
// remain transient to avoid keeping it in memory.
|
||||
yield return describe.Transient<IGlobalFilterProvider, DefaultGlobalFilterProvider>();
|
||||
yield return describe.Transient<INestedProviderManager<FilterProviderContext>,
|
||||
NestedProviderManager<FilterProviderContext>>();
|
||||
yield return describe.Transient<INestedProvider<FilterProviderContext>, DefaultFilterProvider>();
|
||||
yield return describe.Transient<IFilterProvider, DefaultFilterProvider>();
|
||||
|
||||
yield return describe.Transient<FormatFilter, FormatFilter>();
|
||||
// Dataflow - ModelBinding, Validation and Formatting
|
||||
|
|
@ -165,10 +157,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
yield return describe.Singleton<IViewComponentActivator, DefaultViewComponentActivator>();
|
||||
|
||||
yield return describe.Transient<IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>();
|
||||
yield return describe.Transient<INestedProviderManager<ViewComponentInvokerProviderContext>,
|
||||
NestedProviderManager<ViewComponentInvokerProviderContext>>();
|
||||
yield return describe.Transient<INestedProvider<ViewComponentInvokerProviderContext>,
|
||||
DefaultViewComponentInvokerProvider>();
|
||||
yield return describe.Transient<IViewComponentInvokerProvider, DefaultViewComponentInvokerProvider>();
|
||||
yield return describe.Transient<IViewComponentHelper, DefaultViewComponentHelper>();
|
||||
|
||||
// Security and Authorization
|
||||
|
|
@ -178,12 +167,9 @@ namespace Microsoft.AspNet.Mvc
|
|||
DefaultAntiForgeryAdditionalDataProvider>();
|
||||
|
||||
// Api Description
|
||||
yield return describe.Transient<INestedProviderManager<ApiDescriptionProviderContext>,
|
||||
NestedProviderManager<ApiDescriptionProviderContext>>();
|
||||
yield return describe.Singleton<IApiDescriptionGroupCollectionProvider,
|
||||
ApiDescriptionGroupCollectionProvider>();
|
||||
yield return describe.Transient<INestedProvider<ApiDescriptionProviderContext>,
|
||||
DefaultApiDescriptionProvider>();
|
||||
yield return describe.Transient<IApiDescriptionProvider, DefaultApiDescriptionProvider>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
{
|
||||
"compilationOptions": {
|
||||
"warningsAsErrors": "true"
|
||||
"warningsAsErrors": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" },
|
||||
"Microsoft.AspNet.Testing": "1.0.0-*",
|
||||
"Microsoft.Framework.CopyOnWriteDictionary.Internal": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Framework.NotNullAttribute.Internal": { "version": "1.0.0-*", "type": "build" },
|
||||
"xunit.runner.kre": "1.0.0-*"
|
||||
"xunit.runner.kre": "1.0.0-*",
|
||||
"Microsoft.Framework.DependencyInjection": "1.0.0-*"
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.kre"
|
||||
|
|
|
|||
|
|
@ -2,6 +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.ActionConstraints;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Logging
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNet.Mvc.ApplicationModels;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Description;
|
||||
using Microsoft.AspNet.Mvc.Routing;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Core;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.AspNet.Testing;
|
||||
|
|
@ -1976,9 +1978,9 @@ namespace Microsoft.AspNet.Mvc
|
|||
routeData: new RouteData(),
|
||||
actionDescriptor: actionDescriptor);
|
||||
|
||||
var filterProvider = new Mock<INestedProviderManager<FilterProviderContext>>(MockBehavior.Strict);
|
||||
var filterProvider = new Mock<IFilterProvider>(MockBehavior.Strict);
|
||||
filterProvider
|
||||
.Setup(fp => fp.Invoke(It.IsAny<FilterProviderContext>()))
|
||||
.Setup(fp => fp.OnProvidersExecuting(It.IsAny<FilterProviderContext>()))
|
||||
.Callback<FilterProviderContext>(context =>
|
||||
{
|
||||
foreach (var filter in filters.Select(f => new FilterItem(null, f)))
|
||||
|
|
@ -1987,6 +1989,13 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
});
|
||||
|
||||
filterProvider.Setup(fp => fp.OnProvidersExecuted(It.IsAny<FilterProviderContext>()))
|
||||
.Verifiable();
|
||||
|
||||
filterProvider.SetupGet(fp => fp.Order)
|
||||
.Returns(DefaultOrder.DefaultFrameworkSortOrder);
|
||||
|
||||
|
||||
var inputFormattersProvider = new Mock<IInputFormattersProvider>();
|
||||
inputFormattersProvider.SetupGet(o => o.InputFormatters)
|
||||
.Returns(new List<IInputFormatter>());
|
||||
|
|
@ -1995,7 +2004,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
.Returns(new List<IExcludeTypeValidationFilter>());
|
||||
var invoker = new TestControllerActionInvoker(
|
||||
actionContext,
|
||||
filterProvider.Object,
|
||||
new[] { filterProvider.Object },
|
||||
new MockControllerFactory(this),
|
||||
actionDescriptor,
|
||||
inputFormattersProvider.Object,
|
||||
|
|
@ -2047,7 +2056,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var metadataProvider = new EmptyModelMetadataProvider();
|
||||
var invoker = new ControllerActionInvoker(
|
||||
actionContext,
|
||||
Mock.Of<INestedProviderManager<FilterProviderContext>>(),
|
||||
new List<IFilterProvider>(),
|
||||
controllerFactory.Object,
|
||||
actionDescriptor,
|
||||
inputFormattersProvider.Object,
|
||||
|
|
@ -2147,7 +2156,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
public TestControllerActionInvoker(
|
||||
ActionContext actionContext,
|
||||
INestedProviderManager<FilterProviderContext> filterProvider,
|
||||
IFilterProvider[] filterProvider,
|
||||
MockControllerFactory controllerFactory,
|
||||
ControllerActionDescriptor descriptor,
|
||||
IInputFormattersProvider inputFormattersProvider,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNet.Mvc.ApplicationModels;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Security;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.DependencyInjection.NestedProviders;
|
||||
using Microsoft.Framework.Logging;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -109,12 +109,15 @@ namespace Microsoft.AspNet.Mvc.Logging
|
|||
private void CreateActionDescriptors(ILoggerFactory loggerFactory, params TypeInfo[] controllerTypeInfo)
|
||||
{
|
||||
var actionDescriptorProvider = GetProvider(loggerFactory, controllerTypeInfo);
|
||||
var descriptorProvider =
|
||||
new NestedProviderManager<ActionDescriptorProviderContext>(new[] { actionDescriptorProvider });
|
||||
|
||||
// service container does not work quite like our built in Depenency Injection container.
|
||||
var serviceContainer = new ServiceContainer();
|
||||
serviceContainer.AddService(typeof(INestedProviderManager<ActionDescriptorProviderContext>),
|
||||
descriptorProvider);
|
||||
var list = new List<IActionDescriptorProvider>()
|
||||
{
|
||||
actionDescriptorProvider,
|
||||
};
|
||||
|
||||
serviceContainer.AddService(typeof(IEnumerable<IActionDescriptorProvider>), list);
|
||||
|
||||
var actionCollectionDescriptorProvider = new DefaultActionDescriptorsCollectionProvider(serviceContainer, loggerFactory);
|
||||
var descriptors = actionCollectionDescriptorProvider.ActionDescriptors;
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ using System.Reflection;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Core;
|
||||
using Microsoft.AspNet.Mvc.ActionConstraints;
|
||||
using Microsoft.AspNet.Mvc.ApplicationModels;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Logging;
|
||||
using Microsoft.AspNet.Mvc.Routing;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.DependencyInjection.NestedProviders;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.Logging;
|
||||
using Moq;
|
||||
|
|
@ -733,26 +733,27 @@ namespace Microsoft.AspNet.Mvc
|
|||
private async Task<ActionDescriptor> InvokeActionSelector(RouteContext context)
|
||||
{
|
||||
var actionDescriptorProvider = GetActionDescriptorProvider();
|
||||
var descriptorProvider =
|
||||
new NestedProviderManager<ActionDescriptorProviderContext>(new[] { actionDescriptorProvider });
|
||||
|
||||
// service container does not work quite like our built in Depenency Injection container.
|
||||
var serviceContainer = new ServiceContainer();
|
||||
serviceContainer.AddService(typeof(INestedProviderManager<ActionDescriptorProviderContext>),
|
||||
descriptorProvider);
|
||||
var list = new List<IActionDescriptorProvider>()
|
||||
{
|
||||
actionDescriptorProvider,
|
||||
};
|
||||
|
||||
serviceContainer.AddService(typeof(IEnumerable<IActionDescriptorProvider>), list);
|
||||
|
||||
var actionCollectionDescriptorProvider = new DefaultActionDescriptorsCollectionProvider(serviceContainer, new NullLoggerFactory());
|
||||
var decisionTreeProvider = new ActionSelectorDecisionTreeProvider(actionCollectionDescriptorProvider);
|
||||
|
||||
var actionConstraintProvider = new NestedProviderManager<ActionConstraintProviderContext>(
|
||||
new INestedProvider<ActionConstraintProviderContext>[]
|
||||
{
|
||||
new DefaultActionConstraintProvider(),
|
||||
});
|
||||
var actionConstraintProviders = new IActionConstraintProvider[] {
|
||||
new DefaultActionConstraintProvider(),
|
||||
};
|
||||
|
||||
var defaultActionSelector = new DefaultActionSelector(
|
||||
actionCollectionDescriptorProvider,
|
||||
decisionTreeProvider,
|
||||
actionConstraintProvider,
|
||||
actionConstraintProviders,
|
||||
NullLoggerFactory.Instance);
|
||||
|
||||
return await defaultActionSelector.SelectAsync(context);
|
||||
|
|
@ -829,17 +830,15 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
var decisionTreeProvider = new ActionSelectorDecisionTreeProvider(actionProvider.Object);
|
||||
|
||||
var actionConstraintProvider = new NestedProviderManager<ActionConstraintProviderContext>(
|
||||
new INestedProvider<ActionConstraintProviderContext>[]
|
||||
{
|
||||
new DefaultActionConstraintProvider(),
|
||||
new BooleanConstraintProvider(),
|
||||
});
|
||||
var actionConstraintProviders = new IActionConstraintProvider[] {
|
||||
new DefaultActionConstraintProvider(),
|
||||
new BooleanConstraintProvider(),
|
||||
};
|
||||
|
||||
return new DefaultActionSelector(
|
||||
actionProvider.Object,
|
||||
decisionTreeProvider,
|
||||
actionConstraintProvider,
|
||||
actionConstraintProviders,
|
||||
loggerFactory);
|
||||
}
|
||||
|
||||
|
|
@ -932,11 +931,11 @@ namespace Microsoft.AspNet.Mvc
|
|||
public bool Pass { get; set; }
|
||||
}
|
||||
|
||||
private class BooleanConstraintProvider : INestedProvider<ActionConstraintProviderContext>
|
||||
private class BooleanConstraintProvider : IActionConstraintProvider
|
||||
{
|
||||
public int Order { get; set; }
|
||||
|
||||
public void Invoke(ActionConstraintProviderContext context, Action callNext)
|
||||
public void OnProvidersExecuting(ActionConstraintProviderContext context)
|
||||
{
|
||||
foreach (var item in context.Results)
|
||||
{
|
||||
|
|
@ -947,8 +946,10 @@ namespace Microsoft.AspNet.Mvc
|
|||
item.Constraint = new BooleanConstraint() { Pass = marker.Pass };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
callNext();
|
||||
public void OnProvidersExecuted(ActionConstraintProviderContext context)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -925,7 +925,9 @@ namespace Microsoft.AspNet.Mvc.Description
|
|||
constraintResolver.Object,
|
||||
modelMetadataProvider);
|
||||
|
||||
provider.Invoke(context, () => { });
|
||||
provider.OnProvidersExecuting(context);
|
||||
provider.OnProvidersExecuted(context);
|
||||
|
||||
return new ReadOnlyCollection<ApiDescription>(context.Results);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ namespace Microsoft.AspNet.Mvc.Filters
|
|||
var provider = CreateProvider();
|
||||
|
||||
// Act
|
||||
provider.Invoke(context, () => { });
|
||||
provider.OnProvidersExecuting(context);
|
||||
provider.OnProvidersExecuted(context);
|
||||
|
||||
var results = context.Results;
|
||||
|
||||
// Assert
|
||||
|
|
@ -57,7 +59,9 @@ namespace Microsoft.AspNet.Mvc.Filters
|
|||
var provider = CreateProvider();
|
||||
|
||||
// Act
|
||||
provider.Invoke(context, () => { });
|
||||
provider.OnProvidersExecuting(context);
|
||||
provider.OnProvidersExecuted(context);
|
||||
|
||||
var results = context.Results;
|
||||
|
||||
// Assert
|
||||
|
|
@ -88,7 +92,8 @@ namespace Microsoft.AspNet.Mvc.Filters
|
|||
var provider = CreateProvider();
|
||||
|
||||
// Act
|
||||
provider.Invoke(context, () => { });
|
||||
provider.OnProvidersExecuting(context);
|
||||
provider.OnProvidersExecuted(context);
|
||||
var results = context.Results;
|
||||
|
||||
// Assert
|
||||
|
|
@ -118,7 +123,8 @@ namespace Microsoft.AspNet.Mvc.Filters
|
|||
var provider = CreateProvider();
|
||||
|
||||
// Act
|
||||
provider.Invoke(context, () => { });
|
||||
provider.OnProvidersExecuting(context);
|
||||
provider.OnProvidersExecuted(context);
|
||||
var results = context.Results;
|
||||
|
||||
// Assert
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -151,17 +151,25 @@ namespace Microsoft.AspNet.Routing.Tests
|
|||
|
||||
private static HttpContext GetHttpContext(ActionDescriptor actionDescriptor)
|
||||
{
|
||||
var actionProvider = new Mock<INestedProviderManager<ActionDescriptorProviderContext>>(
|
||||
MockBehavior.Strict);
|
||||
var actionProvider = new Mock<IActionDescriptorProvider>(MockBehavior.Strict);
|
||||
|
||||
actionProvider
|
||||
.Setup(p => p.Invoke(It.IsAny<ActionDescriptorProviderContext>()))
|
||||
.SetupGet(p => p.Order)
|
||||
.Returns(DefaultOrder.DefaultFrameworkSortOrder);
|
||||
|
||||
actionProvider
|
||||
.Setup(p => p.OnProvidersExecuting(It.IsAny<ActionDescriptorProviderContext>()))
|
||||
.Callback<ActionDescriptorProviderContext>(c => c.Results.Add(actionDescriptor));
|
||||
|
||||
actionProvider
|
||||
.Setup(p => p.OnProvidersExecuted(It.IsAny<ActionDescriptorProviderContext>()))
|
||||
.Verifiable();
|
||||
|
||||
var context = new Mock<HttpContext>();
|
||||
context.Setup(o => o.RequestServices
|
||||
.GetService(typeof(INestedProviderManager<ActionDescriptorProviderContext>)))
|
||||
.Returns(actionProvider.Object);
|
||||
.GetService(typeof(IEnumerable<IActionDescriptorProvider>)))
|
||||
.Returns(new[] { actionProvider.Object });
|
||||
|
||||
context.Setup(o => o.RequestServices
|
||||
.GetService(typeof(IActionDescriptorsCollectionProvider)))
|
||||
.Returns(new DefaultActionDescriptorsCollectionProvider(context.Object.RequestServices, new NullLoggerFactory()));
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@ using System;
|
|||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Mvc.ActionConstraints;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Description;
|
||||
using Microsoft.AspNet.Mvc.Razor;
|
||||
using Microsoft.AspNet.Mvc.ViewComponents;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -21,13 +23,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
private readonly Action<IApplicationBuilder> _app = new BasicWebSite.Startup().Configure;
|
||||
|
||||
[Theory]
|
||||
[InlineData(typeof(INestedProvider<ActionDescriptorProviderContext>), typeof(ControllerActionDescriptorProvider), -1000)]
|
||||
[InlineData(typeof(INestedProvider<ActionInvokerProviderContext>), (Type)null, -1000)]
|
||||
[InlineData(typeof(INestedProvider<ApiDescriptionProviderContext>), (Type)null, -1000)]
|
||||
[InlineData(typeof(INestedProvider<FilterProviderContext>), (Type)null, -1000)]
|
||||
[InlineData(typeof(INestedProvider<ViewComponentInvokerProviderContext>), (Type)null, -1000)]
|
||||
[InlineData(typeof(IConfigureOptions<RazorViewEngineOptions>), (Type)null, -1000)]
|
||||
[InlineData(typeof(IConfigureOptions<MvcOptions>), (Type)null, -1000)]
|
||||
[InlineData(typeof(IActionDescriptorProvider), typeof(ControllerActionDescriptorProvider), -1000)]
|
||||
[InlineData(typeof(IActionInvokerProvider), null, -1000)]
|
||||
[InlineData(typeof(IApiDescriptionProvider), null, -1000)]
|
||||
[InlineData(typeof(IFilterProvider), null, -1000)]
|
||||
[InlineData(typeof(IViewComponentInvokerProvider), null, -1000)]
|
||||
[InlineData(typeof(IActionConstraintProvider), null, -1000)]
|
||||
[InlineData(typeof(IConfigureOptions<RazorViewEngineOptions>), null, -1000)]
|
||||
[InlineData(typeof(IConfigureOptions<MvcOptions>), null, -1000)]
|
||||
public async Task ServiceOrder_GetOrder(Type serviceType, Type actualType, int order)
|
||||
{
|
||||
// Arrange
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ using Microsoft.AspNet.Mvc.ApplicationModels;
|
|||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.Filters;
|
||||
using Microsoft.AspNet.Mvc.WebApiCompatShim;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.DependencyInjection.NestedProviders;
|
||||
using Microsoft.Framework.Logging;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
using Moq;
|
||||
|
|
@ -30,7 +28,7 @@ namespace System.Web.Http
|
|||
|
||||
// Act
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
provider.Invoke(context);
|
||||
Invoke(provider, context);
|
||||
|
||||
var results = context.Results.Cast<ControllerActionDescriptor>();
|
||||
|
||||
|
|
@ -49,7 +47,7 @@ namespace System.Web.Http
|
|||
|
||||
// Act
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
provider.Invoke(context);
|
||||
Invoke(provider, context);
|
||||
|
||||
var results = context.Results.Cast<ControllerActionDescriptor>();
|
||||
|
||||
|
|
@ -68,7 +66,7 @@ namespace System.Web.Http
|
|||
|
||||
// Act
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
provider.Invoke(context);
|
||||
Invoke(provider, context);
|
||||
|
||||
var results = context.Results.Cast<ControllerActionDescriptor>();
|
||||
|
||||
|
|
@ -104,7 +102,7 @@ namespace System.Web.Http
|
|||
|
||||
// Act
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
provider.Invoke(context);
|
||||
Invoke(provider, context);
|
||||
|
||||
var results = context.Results.Cast<ControllerActionDescriptor>();
|
||||
|
||||
|
|
@ -140,7 +138,7 @@ namespace System.Web.Http
|
|||
|
||||
// Act
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
provider.Invoke(context);
|
||||
Invoke(provider, context);
|
||||
|
||||
var results = context.Results.Cast<ControllerActionDescriptor>();
|
||||
|
||||
|
|
@ -177,7 +175,7 @@ namespace System.Web.Http
|
|||
|
||||
// Act
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
provider.Invoke(context);
|
||||
Invoke(provider, context);
|
||||
|
||||
var results = context.Results.Cast<ControllerActionDescriptor>();
|
||||
|
||||
|
|
@ -213,7 +211,7 @@ namespace System.Web.Http
|
|||
|
||||
// Act
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
provider.Invoke(context);
|
||||
Invoke(provider, context);
|
||||
|
||||
var results = context.Results.Cast<ControllerActionDescriptor>();
|
||||
|
||||
|
|
@ -238,7 +236,7 @@ namespace System.Web.Http
|
|||
|
||||
// Act
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
provider.Invoke(context);
|
||||
Invoke(provider, context);
|
||||
|
||||
var results = context.Results.Cast<ControllerActionDescriptor>();
|
||||
|
||||
|
|
@ -263,7 +261,7 @@ namespace System.Web.Http
|
|||
|
||||
// Act
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
provider.Invoke(context);
|
||||
Invoke(provider, context);
|
||||
|
||||
var results = context.Results.Cast<ControllerActionDescriptor>();
|
||||
|
||||
|
|
@ -291,7 +289,7 @@ namespace System.Web.Http
|
|||
|
||||
// Act
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
provider.Invoke(context);
|
||||
Invoke(provider, context);
|
||||
|
||||
var results = context.Results.Cast<ControllerActionDescriptor>();
|
||||
|
||||
|
|
@ -318,7 +316,7 @@ namespace System.Web.Http
|
|||
|
||||
// Act
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
provider.Invoke(context);
|
||||
Invoke(provider, context);
|
||||
|
||||
var results = context.Results.Cast<ControllerActionDescriptor>();
|
||||
|
||||
|
|
@ -347,7 +345,7 @@ namespace System.Web.Http
|
|||
|
||||
// Act
|
||||
var context = new ActionDescriptorProviderContext();
|
||||
provider.Invoke(context);
|
||||
Invoke(provider, context);
|
||||
|
||||
var results = context.Results.Cast<ControllerActionDescriptor>();
|
||||
|
||||
|
|
@ -367,7 +365,7 @@ namespace System.Web.Http
|
|||
}
|
||||
}
|
||||
|
||||
private INestedProviderManager<ActionDescriptorProviderContext> CreateProvider()
|
||||
private ControllerActionDescriptorProvider CreateProvider()
|
||||
{
|
||||
var assemblyProvider = new FixedSetAssemblyProvider();
|
||||
assemblyProvider.CandidateAssemblies.Add(GetType().GetTypeInfo().Assembly);
|
||||
|
|
@ -398,11 +396,13 @@ namespace System.Web.Http
|
|||
optionsAccessor.Object,
|
||||
new NullLoggerFactory());
|
||||
|
||||
return new NestedProviderManager<ActionDescriptorProviderContext>(
|
||||
new INestedProvider<ActionDescriptorProviderContext>[]
|
||||
{
|
||||
provider
|
||||
});
|
||||
return provider;
|
||||
}
|
||||
|
||||
private void Invoke(ControllerActionDescriptorProvider provider, ActionDescriptorProviderContext context)
|
||||
{
|
||||
provider.OnProvidersExecuting(context);
|
||||
provider.OnProvidersExecuted(context);
|
||||
}
|
||||
|
||||
private class NamespaceFilteredControllerTypeProvider : DefaultControllerTypeProvider
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
|
||||
namespace BasicWebSite
|
||||
{
|
||||
|
|
@ -29,10 +30,12 @@ namespace BasicWebSite
|
|||
}
|
||||
}
|
||||
|
||||
public void Invoke(ActionDescriptorProviderContext context, Action callNext)
|
||||
public void OnProvidersExecuting(ActionDescriptorProviderContext context)
|
||||
{
|
||||
callNext();
|
||||
}
|
||||
|
||||
public void OnProvidersExecuted(ActionDescriptorProviderContext context)
|
||||
{
|
||||
if (context.Results.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("No actions found!");
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
|
||||
namespace BasicWebSite
|
||||
{
|
||||
|
|
@ -11,9 +13,9 @@ namespace BasicWebSite
|
|||
{
|
||||
private readonly ActionDescriptorCreationCounter _counterService;
|
||||
|
||||
public MonitorController(INestedProvider<ActionDescriptorProviderContext> counterService)
|
||||
public MonitorController(IEnumerable<IActionDescriptorProvider> providers)
|
||||
{
|
||||
_counterService = (ActionDescriptorCreationCounter)counterService;
|
||||
_counterService = providers.OfType<ActionDescriptorCreationCounter>().Single();
|
||||
}
|
||||
|
||||
public IActionResult CountActionDescriptorInvocations()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace BasicWebSite
|
||||
|
|
@ -19,7 +20,7 @@ namespace BasicWebSite
|
|||
// Add MVC services to the services container
|
||||
services.AddMvc(configuration);
|
||||
|
||||
services.AddSingleton<INestedProvider<ActionDescriptorProviderContext>, ActionDescriptorCreationCounter>();
|
||||
services.AddSingleton<IActionDescriptorProvider, ActionDescriptorCreationCounter>();
|
||||
|
||||
services.ConfigureMvcOptions(options =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.ActionConstraints;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace RequestServicesWebSite
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.ActionConstraints;
|
||||
|
||||
namespace VersioningWebSite
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.ActionConstraints;
|
||||
|
||||
namespace VersioningWebSite
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue