Remove INestedProviderXXX

React to aspnet/DependencyInjection#179
This commit is contained in:
Yishai Galatzer 2015-02-23 15:16:06 -08:00
parent 36c5efd0e2
commit ed8e5716ea
54 changed files with 368 additions and 217 deletions

View File

@ -3,6 +3,7 @@
using System; using System;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.WebApiCompatShim; using Microsoft.AspNet.Mvc.WebApiCompatShim;
using MvcSample.Web.Models; using MvcSample.Web.Models;

View File

@ -3,7 +3,7 @@
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.ActionConstraints
{ {
/// <summary> /// <summary>
/// Represents an <see cref="IActionConstraintMetadata"/> with or without a corresponding /// Represents an <see cref="IActionConstraintMetadata"/> with or without a corresponding

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.ActionConstraints
{ {
/// <summary> /// <summary>
/// Context for an action constraint provider. /// Context for an action constraint provider.

View File

@ -2,20 +2,19 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.ActionConstraints
{ {
/// <summary> /// <summary>
/// A default implementation of <see cref="INestedProvider{ActionConstraintProviderContext}"/>. /// A default implementation of <see cref="IActionConstraintProvider"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This provider is able to provide an <see cref="IActionConstraint"/> instance when the /// This provider is able to provide an <see cref="IActionConstraint"/> instance when the
/// <see cref="IActionConstraintMetadata"/> implements <see cref="IActionConstraint"/> or /// <see cref="IActionConstraintMetadata"/> implements <see cref="IActionConstraint"/> or
/// <see cref="IActionConstraintFactory"/>/ /// <see cref="IActionConstraintFactory"/>/
/// </remarks> /// </remarks>
public class DefaultActionConstraintProvider : INestedProvider<ActionConstraintProviderContext> public class DefaultActionConstraintProvider : IActionConstraintProvider
{ {
/// <inheritdoc /> /// <inheritdoc />
public int Order public int Order
@ -24,14 +23,17 @@ namespace Microsoft.AspNet.Mvc
} }
/// <inheritdoc /> /// <inheritdoc />
public void Invoke([NotNull] ActionConstraintProviderContext context, [NotNull] Action callNext) public void OnProvidersExecuting([NotNull] ActionConstraintProviderContext context)
{ {
foreach (var item in context.Results) foreach (var item in context.Results)
{ {
ProvideConstraint(item, context.HttpContext.RequestServices); ProvideConstraint(item, context.HttpContext.RequestServices);
} }
}
callNext(); /// <inheritdoc />
public void OnProvidersExecuted([NotNull] ActionConstraintProviderContext context)
{
} }
private void ProvideConstraint(ActionConstraintItem item, IServiceProvider services) private void ProvideConstraint(ActionConstraintItem item, IServiceProvider services)

View File

@ -3,7 +3,7 @@
using System; using System;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.ActionConstraints
{ {
/// <summary> /// <summary>
/// A factory for <see cref="IActionConstraint"/>. /// A factory for <see cref="IActionConstraint"/>.

View File

@ -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);
}
}

View File

@ -3,15 +3,10 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Core
{ {
public class ActionDescriptorProviderContext public class ActionDescriptorProviderContext
{ {
public ActionDescriptorProviderContext() public IList<ActionDescriptor> Results { get; } = new List<ActionDescriptor>();
{
Results = new List<ActionDescriptor>();
}
public IList<ActionDescriptor> Results { get; }
} }
} }

View File

@ -1,23 +1,34 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // 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. // 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 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) public IActionInvoker CreateInvoker(ActionContext actionContext)
{ {
var context = new ActionInvokerProviderContext(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; return context.Result;
} }
} }

View File

@ -3,16 +3,16 @@
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Core
{ {
public class ActionInvokerProviderContext public class ActionInvokerProviderContext
{ {
public ActionInvokerProviderContext([NotNull]ActionContext actionContext) public ActionInvokerProviderContext([NotNull] ActionContext actionContext)
{ {
ActionContext = actionContext; ActionContext = actionContext;
} }
public ActionContext ActionContext { get; private set; } public ActionContext ActionContext { get; }
public IActionInvoker Result { get; set; } public IActionInvoker Result { get; set; }
} }

View File

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // 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. // 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.Collections.Generic;
using Microsoft.AspNet.Mvc.ApplicationModels; using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Filters;
@ -10,7 +9,7 @@ using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Core
{ {
public class ControllerActionDescriptorProvider : IActionDescriptorProvider public class ControllerActionDescriptorProvider : IActionDescriptorProvider
{ {
@ -38,17 +37,21 @@ namespace Microsoft.AspNet.Mvc
get { return DefaultOrder.DefaultFrameworkSortOrder; } get { return DefaultOrder.DefaultFrameworkSortOrder; }
} }
public void Invoke(ActionDescriptorProviderContext context, Action callNext) /// <inheritdoc />
public void OnProvidersExecuting ([NotNull] ActionDescriptorProviderContext context)
{ {
foreach (var descriptor in GetDescriptors()) foreach (var descriptor in GetDescriptors())
{ {
context.Results.Add(descriptor); context.Results.Add(descriptor);
} }
callNext();
} }
public IEnumerable<ControllerActionDescriptor> GetDescriptors() /// <inheritdoc />
public void OnProvidersExecuted([NotNull] ActionDescriptorProviderContext context)
{
}
internal protected IEnumerable<ControllerActionDescriptor> GetDescriptors()
{ {
var applicationModel = BuildModel(); var applicationModel = BuildModel();
ApplicationModelConventions.ApplyConventions(applicationModel, _conventions); ApplicationModelConventions.ApplyConventions(applicationModel, _conventions);
@ -62,7 +65,7 @@ namespace Microsoft.AspNet.Mvc
return ControllerActionDescriptorBuilder.Build(applicationModel); return ControllerActionDescriptorBuilder.Build(applicationModel);
} }
public ApplicationModel BuildModel() internal protected ApplicationModel BuildModel()
{ {
var applicationModel = new ApplicationModel(); var applicationModel = new ApplicationModel();
foreach (var filter in _globalFilters) foreach (var filter in _globalFilters)

View File

@ -5,12 +5,11 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Core
{ {
public class ControllerActionInvoker : FilterActionInvoker public class ControllerActionInvoker : FilterActionInvoker
{ {
@ -20,7 +19,7 @@ namespace Microsoft.AspNet.Mvc
public ControllerActionInvoker( public ControllerActionInvoker(
[NotNull] ActionContext actionContext, [NotNull] ActionContext actionContext,
[NotNull] INestedProviderManager<FilterProviderContext> filterProvider, [NotNull] IReadOnlyList<IFilterProvider> filterProviders,
[NotNull] IControllerFactory controllerFactory, [NotNull] IControllerFactory controllerFactory,
[NotNull] ControllerActionDescriptor descriptor, [NotNull] ControllerActionDescriptor descriptor,
[NotNull] IInputFormattersProvider inputFormatterProvider, [NotNull] IInputFormattersProvider inputFormatterProvider,
@ -31,7 +30,7 @@ namespace Microsoft.AspNet.Mvc
[NotNull] IScopedInstance<ActionBindingContext> actionBindingContextAccessor) [NotNull] IScopedInstance<ActionBindingContext> actionBindingContextAccessor)
: base( : base(
actionContext, actionContext,
filterProvider, filterProviders,
inputFormatterProvider, inputFormatterProvider,
modelBinderProvider, modelBinderProvider,
modelValidatorProviderProvider, modelValidatorProviderProvider,

View File

@ -2,16 +2,19 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Core
{ {
public class ControllerActionInvokerProvider : IActionInvokerProvider public class ControllerActionInvokerProvider : IActionInvokerProvider
{ {
private readonly IControllerActionArgumentBinder _argumentBinder; private readonly IControllerActionArgumentBinder _argumentBinder;
private readonly IControllerFactory _controllerFactory; private readonly IControllerFactory _controllerFactory;
private readonly INestedProviderManager<FilterProviderContext> _filterProvider; private readonly IFilterProvider[] _filterProviders;
private readonly IInputFormattersProvider _inputFormattersProvider; private readonly IInputFormattersProvider _inputFormattersProvider;
private readonly IModelBinderProvider _modelBinderProvider; private readonly IModelBinderProvider _modelBinderProvider;
private readonly IModelValidatorProviderProvider _modelValidationProviderProvider; private readonly IModelValidatorProviderProvider _modelValidationProviderProvider;
@ -21,7 +24,7 @@ namespace Microsoft.AspNet.Mvc
public ControllerActionInvokerProvider( public ControllerActionInvokerProvider(
IControllerFactory controllerFactory, IControllerFactory controllerFactory,
IInputFormattersProvider inputFormattersProvider, IInputFormattersProvider inputFormattersProvider,
INestedProviderManager<FilterProviderContext> filterProvider, IEnumerable<IFilterProvider> filterProviders,
IControllerActionArgumentBinder argumentBinder, IControllerActionArgumentBinder argumentBinder,
IModelBinderProvider modelBinderProvider, IModelBinderProvider modelBinderProvider,
IModelValidatorProviderProvider modelValidationProviderProvider, IModelValidatorProviderProvider modelValidationProviderProvider,
@ -30,7 +33,7 @@ namespace Microsoft.AspNet.Mvc
{ {
_controllerFactory = controllerFactory; _controllerFactory = controllerFactory;
_inputFormattersProvider = inputFormattersProvider; _inputFormattersProvider = inputFormattersProvider;
_filterProvider = filterProvider; _filterProviders = filterProviders.OrderBy(item => item.Order).ToArray();
_argumentBinder = argumentBinder; _argumentBinder = argumentBinder;
_modelBinderProvider = modelBinderProvider; _modelBinderProvider = modelBinderProvider;
_modelValidationProviderProvider = modelValidationProviderProvider; _modelValidationProviderProvider = modelValidationProviderProvider;
@ -43,7 +46,8 @@ namespace Microsoft.AspNet.Mvc
get { return DefaultOrder.DefaultFrameworkSortOrder; } 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; var actionDescriptor = context.ActionContext.ActionDescriptor as ControllerActionDescriptor;
@ -51,7 +55,7 @@ namespace Microsoft.AspNet.Mvc
{ {
context.Result = new ControllerActionInvoker( context.Result = new ControllerActionInvoker(
context.ActionContext, context.ActionContext,
_filterProvider, _filterProviders,
_controllerFactory, _controllerFactory,
actionDescriptor, actionDescriptor,
_inputFormattersProvider, _inputFormattersProvider,
@ -61,8 +65,11 @@ namespace Microsoft.AspNet.Mvc
_valueProviderFactoryProvider, _valueProviderFactoryProvider,
_actionBindingContextAccessor); _actionBindingContextAccessor);
} }
}
callNext(); /// <inheritdoc />
public void OnProvidersExecuted([NotNull] ActionInvokerProviderContext context)
{
} }
} }
} }

View File

@ -3,11 +3,12 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.AspNet.Mvc.Logging; using Microsoft.AspNet.Mvc.Logging;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Core
{ {
/// <summary> /// <summary>
/// Default implementation for ActionDescriptors. /// Default implementation for ActionDescriptors.
@ -47,22 +48,33 @@ namespace Microsoft.AspNet.Mvc
private ActionDescriptorsCollection GetCollection() private ActionDescriptorsCollection GetCollection()
{ {
var actionDescriptorProvider = var providers =
_serviceProvider.GetRequiredService<INestedProviderManager<ActionDescriptorProviderContext>>(); _serviceProvider.GetRequiredServices<IActionDescriptorProvider>()
var actionDescriptorProviderContext = new ActionDescriptorProviderContext(); .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)) if (_logger.IsEnabled(LogLevel.Verbose))
{ {
foreach (var actionDescriptor in actionDescriptorProviderContext.Results) foreach (var actionDescriptor in context.Results)
{ {
_logger.WriteVerbose(new ActionDescriptorValues(actionDescriptor)); _logger.WriteVerbose(new ActionDescriptorValues(actionDescriptor));
} }
} }
return new ActionDescriptorsCollection( return new ActionDescriptorsCollection(
new ReadOnlyCollection<ActionDescriptor>(actionDescriptorProviderContext.Results), 0); new ReadOnlyCollection<ActionDescriptor>(context.Results), 0);
} }
} }
} }

View File

@ -6,32 +6,31 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.Logging; using Microsoft.AspNet.Mvc.Logging;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Core
{ {
public class DefaultActionSelector : IActionSelector public class DefaultActionSelector : IActionSelector
{ {
private readonly IActionDescriptorsCollectionProvider _actionDescriptorsCollectionProvider; private readonly IActionDescriptorsCollectionProvider _actionDescriptorsCollectionProvider;
private readonly IActionSelectorDecisionTreeProvider _decisionTreeProvider; private readonly IActionSelectorDecisionTreeProvider _decisionTreeProvider;
private readonly INestedProviderManager<ActionConstraintProviderContext> _actionConstraintProvider; private readonly IActionConstraintProvider[] _actionConstraintProviders;
private ILogger _logger; private ILogger _logger;
public DefaultActionSelector( public DefaultActionSelector(
[NotNull] IActionDescriptorsCollectionProvider actionDescriptorsCollectionProvider, IActionDescriptorsCollectionProvider actionDescriptorsCollectionProvider,
[NotNull] IActionSelectorDecisionTreeProvider decisionTreeProvider, IActionSelectorDecisionTreeProvider decisionTreeProvider,
[NotNull] INestedProviderManager<ActionConstraintProviderContext> actionConstraintProvider, IEnumerable<IActionConstraintProvider> actionConstraintProviders,
[NotNull] ILoggerFactory loggerFactory) ILoggerFactory loggerFactory)
{ {
_actionDescriptorsCollectionProvider = actionDescriptorsCollectionProvider; _actionDescriptorsCollectionProvider = actionDescriptorsCollectionProvider;
_decisionTreeProvider = decisionTreeProvider; _decisionTreeProvider = decisionTreeProvider;
_actionConstraintProvider = actionConstraintProvider; _actionConstraintProviders = actionConstraintProviders.OrderBy(item => item.Order).ToArray();
_logger = loggerFactory.Create<DefaultActionSelector>(); _logger = loggerFactory.Create<DefaultActionSelector>();
} }
@ -265,7 +264,15 @@ namespace Microsoft.AspNet.Mvc
var items = action.ActionConstraints.Select(c => new ActionConstraintItem(c)).ToList(); var items = action.ActionConstraints.Select(c => new ActionConstraintItem(c)).ToList();
var context = new ActionConstraintProviderContext(httpContext, action, items); 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 return
context.Results context.Results

View File

@ -34,6 +34,7 @@ namespace Microsoft.AspNet.Mvc
"Microsoft.AspNet.Mvc.ModelBinding", "Microsoft.AspNet.Mvc.ModelBinding",
"Microsoft.AspNet.Mvc.Razor", "Microsoft.AspNet.Mvc.Razor",
"Microsoft.AspNet.Mvc.Razor.Host", "Microsoft.AspNet.Mvc.Razor.Host",
"Microsoft.AspNet.Mvc.TagHelpers",
}; };
/// <inheritdoc /> /// <inheritdoc />

View File

@ -1,8 +1,8 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // 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. // 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.Linq;
using Microsoft.Framework.DependencyInjection;
namespace Microsoft.AspNet.Mvc.Description namespace Microsoft.AspNet.Mvc.Description
{ {
@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc.Description
public class ApiDescriptionGroupCollectionProvider : IApiDescriptionGroupCollectionProvider public class ApiDescriptionGroupCollectionProvider : IApiDescriptionGroupCollectionProvider
{ {
private readonly IActionDescriptorsCollectionProvider _actionDescriptorCollectionProvider; private readonly IActionDescriptorsCollectionProvider _actionDescriptorCollectionProvider;
private readonly INestedProviderManager<ApiDescriptionProviderContext> _apiDescriptionProvider; private readonly IApiDescriptionProvider[] _apiDescriptionProviders;
private ApiDescriptionGroupCollection _apiDescriptionGroups; private ApiDescriptionGroupCollection _apiDescriptionGroups;
@ -20,15 +20,15 @@ namespace Microsoft.AspNet.Mvc.Description
/// <param name="actionDescriptorCollectionProvider"> /// <param name="actionDescriptorCollectionProvider">
/// The <see cref="IActionDescriptorsCollectionProvider"/>. /// The <see cref="IActionDescriptorsCollectionProvider"/>.
/// </param> /// </param>
/// <param name="apiDescriptionProvider"> /// <param name="apiDescriptionProviders">
/// The <see cref="INestedProviderManager{ApiDescriptionProviderContext}"/>. /// The <see cref="IEnumerable{IApiDescriptionProvider}}"/>.
/// </param> /// </param>
public ApiDescriptionGroupCollectionProvider( public ApiDescriptionGroupCollectionProvider(
IActionDescriptorsCollectionProvider actionDescriptorCollectionProvider, IActionDescriptorsCollectionProvider actionDescriptorCollectionProvider,
INestedProviderManager<ApiDescriptionProviderContext> apiDescriptionProvider) IEnumerable<IApiDescriptionProvider> apiDescriptionProviders)
{ {
_actionDescriptorCollectionProvider = actionDescriptorCollectionProvider; _actionDescriptorCollectionProvider = actionDescriptorCollectionProvider;
_apiDescriptionProvider = apiDescriptionProvider; _apiDescriptionProviders = apiDescriptionProviders.OrderBy(item => item.Order).ToArray();
} }
/// <inheritdoc /> /// <inheritdoc />
@ -49,7 +49,16 @@ namespace Microsoft.AspNet.Mvc.Description
private ApiDescriptionGroupCollection GetCollection(ActionDescriptorsCollection actionDescriptors) private ApiDescriptionGroupCollection GetCollection(ActionDescriptorsCollection actionDescriptors)
{ {
var context = new ApiDescriptionProviderContext(actionDescriptors.Items); 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 var groups = context.Results
.GroupBy(d => d.GroupName) .GroupBy(d => d.GroupName)

View File

@ -8,8 +8,8 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Routing.Template; using Microsoft.AspNet.Routing.Template;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
using Microsoft.Framework.DependencyInjection;
namespace Microsoft.AspNet.Mvc.Description namespace Microsoft.AspNet.Mvc.Description
{ {
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Mvc.Description
/// Implements a provider of <see cref="ApiDescription"/> for actions represented /// Implements a provider of <see cref="ApiDescription"/> for actions represented
/// by <see cref="ControllerActionDescriptor"/>. /// by <see cref="ControllerActionDescriptor"/>.
/// </summary> /// </summary>
public class DefaultApiDescriptionProvider : INestedProvider<ApiDescriptionProviderContext> public class DefaultApiDescriptionProvider : IApiDescriptionProvider
{ {
private readonly IOutputFormattersProvider _formattersProvider; private readonly IOutputFormattersProvider _formattersProvider;
private readonly IModelMetadataProvider _modelMetadataProvider; private readonly IModelMetadataProvider _modelMetadataProvider;
@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Mvc.Description
} }
/// <inheritdoc /> /// <inheritdoc />
public void Invoke(ApiDescriptionProviderContext context, Action callNext) public void OnProvidersExecuting([NotNull] ApiDescriptionProviderContext context)
{ {
foreach (var action in context.Actions.OfType<ControllerActionDescriptor>()) 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( private ApiDescription CreateApiDescription(

View File

@ -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);
}
}

View File

@ -7,16 +7,15 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Runtime.ExceptionServices; using System.Runtime.ExceptionServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Core
{ {
public abstract class FilterActionInvoker : IActionInvoker public abstract class FilterActionInvoker : IActionInvoker
{ {
private readonly INestedProviderManager<FilterProviderContext> _filterProvider; private readonly IReadOnlyList<IFilterProvider> _filterProviders;
private readonly IInputFormattersProvider _inputFormatterProvider; private readonly IInputFormattersProvider _inputFormatterProvider;
private readonly IModelBinderProvider _modelBinderProvider; private readonly IModelBinderProvider _modelBinderProvider;
private readonly IModelValidatorProviderProvider _modelValidatorProviderProvider; private readonly IModelValidatorProviderProvider _modelValidatorProviderProvider;
@ -41,7 +40,7 @@ namespace Microsoft.AspNet.Mvc
public FilterActionInvoker( public FilterActionInvoker(
[NotNull] ActionContext actionContext, [NotNull] ActionContext actionContext,
[NotNull] INestedProviderManager<FilterProviderContext> filterProvider, [NotNull] IReadOnlyList<IFilterProvider> filterProviders,
[NotNull] IInputFormattersProvider inputFormatterProvider, [NotNull] IInputFormattersProvider inputFormatterProvider,
[NotNull] IModelBinderProvider modelBinderProvider, [NotNull] IModelBinderProvider modelBinderProvider,
[NotNull] IModelValidatorProviderProvider modelValidatorProviderProvider, [NotNull] IModelValidatorProviderProvider modelValidatorProviderProvider,
@ -50,7 +49,7 @@ namespace Microsoft.AspNet.Mvc
{ {
ActionContext = actionContext; ActionContext = actionContext;
_filterProvider = filterProvider; _filterProviders = filterProviders;
_inputFormatterProvider = inputFormatterProvider; _inputFormatterProvider = inputFormatterProvider;
_modelBinderProvider = modelBinderProvider; _modelBinderProvider = modelBinderProvider;
_modelValidatorProviderProvider = modelValidatorProviderProvider; _modelValidatorProviderProvider = modelValidatorProviderProvider;
@ -142,13 +141,21 @@ namespace Microsoft.AspNet.Mvc
private IFilter[] GetFilters() private IFilter[] GetFilters()
{ {
var filterProviderContext = new FilterProviderContext( var context = new FilterProviderContext(
ActionContext, ActionContext,
ActionContext.ActionDescriptor.FilterDescriptors.Select(fd => new FilterItem(fd)).ToList()); 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() private async Task InvokeAllAuthorizationFiltersAsync()

View File

@ -4,11 +4,11 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public class DefaultFilterProvider : INestedProvider<FilterProviderContext> public class DefaultFilterProvider : IFilterProvider
{ {
public DefaultFilterProvider(IServiceProvider serviceProvider) public DefaultFilterProvider(IServiceProvider serviceProvider)
{ {
@ -22,7 +22,8 @@ namespace Microsoft.AspNet.Mvc.Filters
protected IServiceProvider ServiceProvider { get; private set; } 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) if (context.ActionContext.ActionDescriptor.FilterDescriptors != null)
{ {
@ -31,11 +32,11 @@ namespace Microsoft.AspNet.Mvc.Filters
ProvideFilter(context, item); ProvideFilter(context, item);
} }
} }
}
if (callNext != null) /// <inheritdoc />
{ public void OnProvidersExecuted([NotNull] FilterProviderContext context)
callNext(); {
}
} }
public virtual void ProvideFilter(FilterProviderContext context, FilterItem filterItem) public virtual void ProvideFilter(FilterProviderContext context, FilterItem filterItem)

View File

@ -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);
}
}

View File

@ -1,11 +1,14 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // 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. // 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);
} }
} }

View File

@ -1,11 +1,14 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // 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. // 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);
} }
} }

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging namespace Microsoft.AspNet.Mvc.Logging

View File

@ -7,7 +7,7 @@ using System.Text;
namespace Microsoft.AspNet.Mvc.Logging namespace Microsoft.AspNet.Mvc.Logging
{ {
/// <summary> /// <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> /// </summary>
public class DefaultActionSelectorSelectAsyncValues public class DefaultActionSelectorSelectAsyncValues
{ {

View File

@ -91,7 +91,7 @@ namespace Microsoft.AspNet.Mvc
public static void RemoveTypesOf<TInstance>([NotNull] this IList<ModelBinderDescriptor> descriptors) public static void RemoveTypesOf<TInstance>([NotNull] this IList<ModelBinderDescriptor> descriptors)
where TInstance : class, IModelBinder 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)) if (descriptors[i].OptionType == typeof(TInstance))
{ {

View File

@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Mvc
public static void RemoveTypesOf<TInstance>([NotNull] this IList<OutputFormatterDescriptor> descriptors) public static void RemoveTypesOf<TInstance>([NotNull] this IList<OutputFormatterDescriptor> descriptors)
where TInstance : class, IOutputFormatter 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)) if (descriptors[i].OptionType == typeof(TInstance))
{ {

View File

@ -95,7 +95,7 @@ namespace Microsoft.AspNet.Mvc
public static void RemoveTypesOf<TInstance>([NotNull] this IList<ValueProviderFactoryDescriptor> descriptors) public static void RemoveTypesOf<TInstance>([NotNull] this IList<ValueProviderFactoryDescriptor> descriptors)
where TInstance : class, IValueProviderFactory 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)) if (descriptors[i].OptionType == typeof(TInstance))
{ {

View File

@ -9,7 +9,7 @@ using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.ViewComponents
{ {
public class DefaultViewComponentHelper : IViewComponentHelper, ICanHasViewContext public class DefaultViewComponentHelper : IViewComponentHelper, ICanHasViewContext
{ {

View File

@ -1,26 +1,37 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // 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. // 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 System.Reflection;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.ViewComponents
{ {
public class DefaultViewComponentInvokerFactory : IViewComponentInvokerFactory public class DefaultViewComponentInvokerFactory : IViewComponentInvokerFactory
{ {
private readonly INestedProviderManager<ViewComponentInvokerProviderContext> _providerManager; private readonly IViewComponentInvokerProvider[] _providers;
public DefaultViewComponentInvokerFactory( 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) public IViewComponentInvoker CreateInstance([NotNull] TypeInfo componentType, object[] args)
{ {
var context = new ViewComponentInvokerProviderContext(componentType, 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; return context.Result;
} }
} }

View File

@ -2,10 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.ViewComponents
{ {
public class DefaultViewComponentInvokerProvider : IViewComponentInvokerProvider public class DefaultViewComponentInvokerProvider : IViewComponentInvokerProvider
{ {
@ -28,7 +27,8 @@ namespace Microsoft.AspNet.Mvc
get { return DefaultOrder.DefaultFrameworkSortOrder; } get { return DefaultOrder.DefaultFrameworkSortOrder; }
} }
public void Invoke([NotNull] ViewComponentInvokerProviderContext context, [NotNull] Action callNext) /// <inheritdoc />
public void OnProvidersExecuting([NotNull] ViewComponentInvokerProviderContext context)
{ {
context.Result = new DefaultViewComponentInvoker( context.Result = new DefaultViewComponentInvoker(
_serviceProvider, _serviceProvider,
@ -36,8 +36,11 @@ namespace Microsoft.AspNet.Mvc
_viewComponentActivator, _viewComponentActivator,
context.ComponentType, context.ComponentType,
context.Arguments); context.Arguments);
}
callNext(); /// <inheritdoc />
public void OnProvidersExecuted([NotNull] ViewComponentInvokerProviderContext context)
{
} }
} }
} }

View File

@ -4,7 +4,7 @@
using System.Reflection; using System.Reflection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.ViewComponents
{ {
public interface IViewComponentInvokerFactory public interface IViewComponentInvokerFactory
{ {

View File

@ -1,11 +1,14 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // 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. // 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);
} }
} }

View File

@ -4,7 +4,7 @@
using System.Reflection; using System.Reflection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.ViewComponents
{ {
public class ViewComponentInvokerProviderContext public class ViewComponentInvokerProviderContext
{ {

View File

@ -2,7 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.ApplicationModels; using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Description; using Microsoft.AspNet.Mvc.Description;
using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Internal; 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.Razor.OptionDescriptors;
using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Mvc.ViewComponents;
using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.Cache.Memory;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.NestedProviders;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc 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 // This provider needs access to the per-request services, but might be used many times for a given
// request. // request.
yield return describe.Transient<INestedProviderManager<ActionConstraintProviderContext>, yield return describe.Transient<IActionConstraintProvider, DefaultActionConstraintProvider>();
NestedProviderManager<ActionConstraintProviderContext>>();
yield return describe.Transient<INestedProvider<ActionConstraintProviderContext>,
DefaultActionConstraintProvider>();
yield return describe.Singleton<IActionSelectorDecisionTreeProvider, ActionSelectorDecisionTreeProvider>(); yield return describe.Singleton<IActionSelectorDecisionTreeProvider, ActionSelectorDecisionTreeProvider>();
yield return describe.Singleton<IActionSelector, DefaultActionSelector>(); yield return describe.Singleton<IActionSelector, DefaultActionSelector>();
yield return describe.Transient<IControllerActionArgumentBinder, DefaultControllerActionArgumentBinder>(); yield return describe.Transient<IControllerActionArgumentBinder, DefaultControllerActionArgumentBinder>();
yield return describe.Transient<IObjectModelValidator, DefaultObjectValidator>(); yield return describe.Transient<IObjectModelValidator, DefaultObjectValidator>();
yield return describe.Transient<INestedProviderManager<ActionDescriptorProviderContext>, yield return describe.Transient<IActionDescriptorProvider, ControllerActionDescriptorProvider>();
NestedProviderManager<ActionDescriptorProviderContext>>();
yield return describe.Transient<INestedProvider<ActionDescriptorProviderContext>,
ControllerActionDescriptorProvider>();
yield return describe.Transient<INestedProviderManager<ActionInvokerProviderContext>, yield return describe.Transient<IActionInvokerProvider,
NestedProviderManager<ActionInvokerProviderContext>>();
yield return describe.Transient<INestedProvider<ActionInvokerProviderContext>,
ControllerActionInvokerProvider>(); ControllerActionInvokerProvider>();
yield return describe.Singleton<IActionDescriptorsCollectionProvider, 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 // The IGlobalFilterProvider is used to build the action descriptors (likely once) and so should
// remain transient to avoid keeping it in memory. // remain transient to avoid keeping it in memory.
yield return describe.Transient<IGlobalFilterProvider, DefaultGlobalFilterProvider>(); yield return describe.Transient<IGlobalFilterProvider, DefaultGlobalFilterProvider>();
yield return describe.Transient<INestedProviderManager<FilterProviderContext>, yield return describe.Transient<IFilterProvider, DefaultFilterProvider>();
NestedProviderManager<FilterProviderContext>>();
yield return describe.Transient<INestedProvider<FilterProviderContext>, DefaultFilterProvider>();
yield return describe.Transient<FormatFilter, FormatFilter>(); yield return describe.Transient<FormatFilter, FormatFilter>();
// Dataflow - ModelBinding, Validation and Formatting // Dataflow - ModelBinding, Validation and Formatting
@ -165,10 +157,7 @@ namespace Microsoft.AspNet.Mvc
yield return describe.Singleton<IViewComponentActivator, DefaultViewComponentActivator>(); yield return describe.Singleton<IViewComponentActivator, DefaultViewComponentActivator>();
yield return describe.Transient<IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>(); yield return describe.Transient<IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>();
yield return describe.Transient<INestedProviderManager<ViewComponentInvokerProviderContext>, yield return describe.Transient<IViewComponentInvokerProvider, DefaultViewComponentInvokerProvider>();
NestedProviderManager<ViewComponentInvokerProviderContext>>();
yield return describe.Transient<INestedProvider<ViewComponentInvokerProviderContext>,
DefaultViewComponentInvokerProvider>();
yield return describe.Transient<IViewComponentHelper, DefaultViewComponentHelper>(); yield return describe.Transient<IViewComponentHelper, DefaultViewComponentHelper>();
// Security and Authorization // Security and Authorization
@ -178,12 +167,9 @@ namespace Microsoft.AspNet.Mvc
DefaultAntiForgeryAdditionalDataProvider>(); DefaultAntiForgeryAdditionalDataProvider>();
// Api Description // Api Description
yield return describe.Transient<INestedProviderManager<ApiDescriptionProviderContext>,
NestedProviderManager<ApiDescriptionProviderContext>>();
yield return describe.Singleton<IApiDescriptionGroupCollectionProvider, yield return describe.Singleton<IApiDescriptionGroupCollectionProvider,
ApiDescriptionGroupCollectionProvider>(); ApiDescriptionGroupCollectionProvider>();
yield return describe.Transient<INestedProvider<ApiDescriptionProviderContext>, yield return describe.Transient<IApiDescriptionProvider, DefaultApiDescriptionProvider>();
DefaultApiDescriptionProvider>();
} }
} }
} }

View File

@ -1,13 +1,14 @@
{ {
"compilationOptions": { "compilationOptions": {
"warningsAsErrors": "true" "warningsAsErrors": true
}, },
"dependencies": { "dependencies": {
"Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" }, "Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" },
"Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*",
"Microsoft.Framework.CopyOnWriteDictionary.Internal": { "version": "1.0.0-*", "type": "build" }, "Microsoft.Framework.CopyOnWriteDictionary.Internal": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.NotNullAttribute.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": { "commands": {
"test": "xunit.runner.kre" "test": "xunit.runner.kre"

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Mvc.Logging namespace Microsoft.AspNet.Mvc.Logging

View File

@ -6,10 +6,10 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Mvc.ApplicationModels; using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Description; using Microsoft.AspNet.Mvc.Description;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
using Moq; using Moq;
using Xunit; using Xunit;

View File

@ -3,12 +3,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Core; using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Testing; using Microsoft.AspNet.Testing;
@ -1976,9 +1978,9 @@ namespace Microsoft.AspNet.Mvc
routeData: new RouteData(), routeData: new RouteData(),
actionDescriptor: actionDescriptor); actionDescriptor: actionDescriptor);
var filterProvider = new Mock<INestedProviderManager<FilterProviderContext>>(MockBehavior.Strict); var filterProvider = new Mock<IFilterProvider>(MockBehavior.Strict);
filterProvider filterProvider
.Setup(fp => fp.Invoke(It.IsAny<FilterProviderContext>())) .Setup(fp => fp.OnProvidersExecuting(It.IsAny<FilterProviderContext>()))
.Callback<FilterProviderContext>(context => .Callback<FilterProviderContext>(context =>
{ {
foreach (var filter in filters.Select(f => new FilterItem(null, f))) 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>(); var inputFormattersProvider = new Mock<IInputFormattersProvider>();
inputFormattersProvider.SetupGet(o => o.InputFormatters) inputFormattersProvider.SetupGet(o => o.InputFormatters)
.Returns(new List<IInputFormatter>()); .Returns(new List<IInputFormatter>());
@ -1995,7 +2004,7 @@ namespace Microsoft.AspNet.Mvc
.Returns(new List<IExcludeTypeValidationFilter>()); .Returns(new List<IExcludeTypeValidationFilter>());
var invoker = new TestControllerActionInvoker( var invoker = new TestControllerActionInvoker(
actionContext, actionContext,
filterProvider.Object, new[] { filterProvider.Object },
new MockControllerFactory(this), new MockControllerFactory(this),
actionDescriptor, actionDescriptor,
inputFormattersProvider.Object, inputFormattersProvider.Object,
@ -2047,7 +2056,7 @@ namespace Microsoft.AspNet.Mvc
var metadataProvider = new EmptyModelMetadataProvider(); var metadataProvider = new EmptyModelMetadataProvider();
var invoker = new ControllerActionInvoker( var invoker = new ControllerActionInvoker(
actionContext, actionContext,
Mock.Of<INestedProviderManager<FilterProviderContext>>(), new List<IFilterProvider>(),
controllerFactory.Object, controllerFactory.Object,
actionDescriptor, actionDescriptor,
inputFormattersProvider.Object, inputFormattersProvider.Object,
@ -2147,7 +2156,7 @@ namespace Microsoft.AspNet.Mvc
{ {
public TestControllerActionInvoker( public TestControllerActionInvoker(
ActionContext actionContext, ActionContext actionContext,
INestedProviderManager<FilterProviderContext> filterProvider, IFilterProvider[] filterProvider,
MockControllerFactory controllerFactory, MockControllerFactory controllerFactory,
ControllerActionDescriptor descriptor, ControllerActionDescriptor descriptor,
IInputFormattersProvider inputFormattersProvider, IInputFormattersProvider inputFormattersProvider,

View File

@ -1,13 +1,13 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // 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. // 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.ComponentModel.Design;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Mvc.ApplicationModels; using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Security; using Microsoft.AspNet.Security;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.NestedProviders;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
using Xunit; using Xunit;
@ -109,12 +109,15 @@ namespace Microsoft.AspNet.Mvc.Logging
private void CreateActionDescriptors(ILoggerFactory loggerFactory, params TypeInfo[] controllerTypeInfo) private void CreateActionDescriptors(ILoggerFactory loggerFactory, params TypeInfo[] controllerTypeInfo)
{ {
var actionDescriptorProvider = GetProvider(loggerFactory, 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(); var serviceContainer = new ServiceContainer();
serviceContainer.AddService(typeof(INestedProviderManager<ActionDescriptorProviderContext>), var list = new List<IActionDescriptorProvider>()
descriptorProvider); {
actionDescriptorProvider,
};
serviceContainer.AddService(typeof(IEnumerable<IActionDescriptorProvider>), list);
var actionCollectionDescriptorProvider = new DefaultActionDescriptorsCollectionProvider(serviceContainer, loggerFactory); var actionCollectionDescriptorProvider = new DefaultActionDescriptorsCollectionProvider(serviceContainer, loggerFactory);
var descriptors = actionCollectionDescriptorProvider.ActionDescriptors; var descriptors = actionCollectionDescriptorProvider.ActionDescriptors;

View File

@ -9,12 +9,12 @@ using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Core; using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.ApplicationModels; using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Logging; using Microsoft.AspNet.Mvc.Logging;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.NestedProviders;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
using Moq; using Moq;
@ -733,26 +733,27 @@ namespace Microsoft.AspNet.Mvc
private async Task<ActionDescriptor> InvokeActionSelector(RouteContext context) private async Task<ActionDescriptor> InvokeActionSelector(RouteContext context)
{ {
var actionDescriptorProvider = GetActionDescriptorProvider(); 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(); var serviceContainer = new ServiceContainer();
serviceContainer.AddService(typeof(INestedProviderManager<ActionDescriptorProviderContext>), var list = new List<IActionDescriptorProvider>()
descriptorProvider); {
actionDescriptorProvider,
};
serviceContainer.AddService(typeof(IEnumerable<IActionDescriptorProvider>), list);
var actionCollectionDescriptorProvider = new DefaultActionDescriptorsCollectionProvider(serviceContainer, new NullLoggerFactory()); var actionCollectionDescriptorProvider = new DefaultActionDescriptorsCollectionProvider(serviceContainer, new NullLoggerFactory());
var decisionTreeProvider = new ActionSelectorDecisionTreeProvider(actionCollectionDescriptorProvider); var decisionTreeProvider = new ActionSelectorDecisionTreeProvider(actionCollectionDescriptorProvider);
var actionConstraintProvider = new NestedProviderManager<ActionConstraintProviderContext>( var actionConstraintProviders = new IActionConstraintProvider[] {
new INestedProvider<ActionConstraintProviderContext>[] new DefaultActionConstraintProvider(),
{ };
new DefaultActionConstraintProvider(),
});
var defaultActionSelector = new DefaultActionSelector( var defaultActionSelector = new DefaultActionSelector(
actionCollectionDescriptorProvider, actionCollectionDescriptorProvider,
decisionTreeProvider, decisionTreeProvider,
actionConstraintProvider, actionConstraintProviders,
NullLoggerFactory.Instance); NullLoggerFactory.Instance);
return await defaultActionSelector.SelectAsync(context); return await defaultActionSelector.SelectAsync(context);
@ -829,17 +830,15 @@ namespace Microsoft.AspNet.Mvc
var decisionTreeProvider = new ActionSelectorDecisionTreeProvider(actionProvider.Object); var decisionTreeProvider = new ActionSelectorDecisionTreeProvider(actionProvider.Object);
var actionConstraintProvider = new NestedProviderManager<ActionConstraintProviderContext>( var actionConstraintProviders = new IActionConstraintProvider[] {
new INestedProvider<ActionConstraintProviderContext>[] new DefaultActionConstraintProvider(),
{ new BooleanConstraintProvider(),
new DefaultActionConstraintProvider(), };
new BooleanConstraintProvider(),
});
return new DefaultActionSelector( return new DefaultActionSelector(
actionProvider.Object, actionProvider.Object,
decisionTreeProvider, decisionTreeProvider,
actionConstraintProvider, actionConstraintProviders,
loggerFactory); loggerFactory);
} }
@ -932,11 +931,11 @@ namespace Microsoft.AspNet.Mvc
public bool Pass { get; set; } public bool Pass { get; set; }
} }
private class BooleanConstraintProvider : INestedProvider<ActionConstraintProviderContext> private class BooleanConstraintProvider : IActionConstraintProvider
{ {
public int Order { get; set; } public int Order { get; set; }
public void Invoke(ActionConstraintProviderContext context, Action callNext) public void OnProvidersExecuting(ActionConstraintProviderContext context)
{ {
foreach (var item in context.Results) foreach (var item in context.Results)
{ {
@ -947,8 +946,10 @@ namespace Microsoft.AspNet.Mvc
item.Constraint = new BooleanConstraint() { Pass = marker.Pass }; item.Constraint = new BooleanConstraint() { Pass = marker.Pass };
} }
} }
}
callNext(); public void OnProvidersExecuted(ActionConstraintProviderContext context)
{
} }
} }

View File

@ -925,7 +925,9 @@ namespace Microsoft.AspNet.Mvc.Description
constraintResolver.Object, constraintResolver.Object,
modelMetadataProvider); modelMetadataProvider);
provider.Invoke(context, () => { }); provider.OnProvidersExecuting(context);
provider.OnProvidersExecuted(context);
return new ReadOnlyCollection<ApiDescription>(context.Results); return new ReadOnlyCollection<ApiDescription>(context.Results);
} }

View File

@ -28,7 +28,9 @@ namespace Microsoft.AspNet.Mvc.Filters
var provider = CreateProvider(); var provider = CreateProvider();
// Act // Act
provider.Invoke(context, () => { }); provider.OnProvidersExecuting(context);
provider.OnProvidersExecuted(context);
var results = context.Results; var results = context.Results;
// Assert // Assert
@ -57,7 +59,9 @@ namespace Microsoft.AspNet.Mvc.Filters
var provider = CreateProvider(); var provider = CreateProvider();
// Act // Act
provider.Invoke(context, () => { }); provider.OnProvidersExecuting(context);
provider.OnProvidersExecuted(context);
var results = context.Results; var results = context.Results;
// Assert // Assert
@ -88,7 +92,8 @@ namespace Microsoft.AspNet.Mvc.Filters
var provider = CreateProvider(); var provider = CreateProvider();
// Act // Act
provider.Invoke(context, () => { }); provider.OnProvidersExecuting(context);
provider.OnProvidersExecuted(context);
var results = context.Results; var results = context.Results;
// Assert // Assert
@ -118,7 +123,8 @@ namespace Microsoft.AspNet.Mvc.Filters
var provider = CreateProvider(); var provider = CreateProvider();
// Act // Act
provider.Invoke(context, () => { }); provider.OnProvidersExecuting(context);
provider.OnProvidersExecuted(context);
var results = context.Results; var results = context.Results;
// Assert // Assert

View File

@ -6,7 +6,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.Framework.DependencyInjection; using Microsoft.AspNet.Mvc.Core;
using Moq; using Moq;
using Xunit; using Xunit;
@ -151,17 +151,25 @@ namespace Microsoft.AspNet.Routing.Tests
private static HttpContext GetHttpContext(ActionDescriptor actionDescriptor) private static HttpContext GetHttpContext(ActionDescriptor actionDescriptor)
{ {
var actionProvider = new Mock<INestedProviderManager<ActionDescriptorProviderContext>>( var actionProvider = new Mock<IActionDescriptorProvider>(MockBehavior.Strict);
MockBehavior.Strict);
actionProvider 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)); .Callback<ActionDescriptorProviderContext>(c => c.Results.Add(actionDescriptor));
actionProvider
.Setup(p => p.OnProvidersExecuted(It.IsAny<ActionDescriptorProviderContext>()))
.Verifiable();
var context = new Mock<HttpContext>(); var context = new Mock<HttpContext>();
context.Setup(o => o.RequestServices context.Setup(o => o.RequestServices
.GetService(typeof(INestedProviderManager<ActionDescriptorProviderContext>))) .GetService(typeof(IEnumerable<IActionDescriptorProvider>)))
.Returns(actionProvider.Object); .Returns(new[] { actionProvider.Object });
context.Setup(o => o.RequestServices context.Setup(o => o.RequestServices
.GetService(typeof(IActionDescriptorsCollectionProvider))) .GetService(typeof(IActionDescriptorsCollectionProvider)))
.Returns(new DefaultActionDescriptorsCollectionProvider(context.Object.RequestServices, new NullLoggerFactory())); .Returns(new DefaultActionDescriptorsCollectionProvider(context.Object.RequestServices, new NullLoggerFactory()));

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -5,10 +5,12 @@ using System;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Description; using Microsoft.AspNet.Mvc.Description;
using Microsoft.AspNet.Mvc.Razor; using Microsoft.AspNet.Mvc.Razor;
using Microsoft.AspNet.Mvc.ViewComponents;
using Microsoft.AspNet.TestHost; using Microsoft.AspNet.TestHost;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
using Xunit; using Xunit;
@ -21,13 +23,14 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
private readonly Action<IApplicationBuilder> _app = new BasicWebSite.Startup().Configure; private readonly Action<IApplicationBuilder> _app = new BasicWebSite.Startup().Configure;
[Theory] [Theory]
[InlineData(typeof(INestedProvider<ActionDescriptorProviderContext>), typeof(ControllerActionDescriptorProvider), -1000)] [InlineData(typeof(IActionDescriptorProvider), typeof(ControllerActionDescriptorProvider), -1000)]
[InlineData(typeof(INestedProvider<ActionInvokerProviderContext>), (Type)null, -1000)] [InlineData(typeof(IActionInvokerProvider), null, -1000)]
[InlineData(typeof(INestedProvider<ApiDescriptionProviderContext>), (Type)null, -1000)] [InlineData(typeof(IApiDescriptionProvider), null, -1000)]
[InlineData(typeof(INestedProvider<FilterProviderContext>), (Type)null, -1000)] [InlineData(typeof(IFilterProvider), null, -1000)]
[InlineData(typeof(INestedProvider<ViewComponentInvokerProviderContext>), (Type)null, -1000)] [InlineData(typeof(IViewComponentInvokerProvider), null, -1000)]
[InlineData(typeof(IConfigureOptions<RazorViewEngineOptions>), (Type)null, -1000)] [InlineData(typeof(IActionConstraintProvider), null, -1000)]
[InlineData(typeof(IConfigureOptions<MvcOptions>), (Type)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) public async Task ServiceOrder_GetOrder(Type serviceType, Type actualType, int order)
{ {
// Arrange // Arrange

View File

@ -11,8 +11,6 @@ using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.WebApiCompatShim; using Microsoft.AspNet.Mvc.WebApiCompatShim;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.NestedProviders;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
using Moq; using Moq;
@ -30,7 +28,7 @@ namespace System.Web.Http
// Act // Act
var context = new ActionDescriptorProviderContext(); var context = new ActionDescriptorProviderContext();
provider.Invoke(context); Invoke(provider, context);
var results = context.Results.Cast<ControllerActionDescriptor>(); var results = context.Results.Cast<ControllerActionDescriptor>();
@ -49,7 +47,7 @@ namespace System.Web.Http
// Act // Act
var context = new ActionDescriptorProviderContext(); var context = new ActionDescriptorProviderContext();
provider.Invoke(context); Invoke(provider, context);
var results = context.Results.Cast<ControllerActionDescriptor>(); var results = context.Results.Cast<ControllerActionDescriptor>();
@ -68,7 +66,7 @@ namespace System.Web.Http
// Act // Act
var context = new ActionDescriptorProviderContext(); var context = new ActionDescriptorProviderContext();
provider.Invoke(context); Invoke(provider, context);
var results = context.Results.Cast<ControllerActionDescriptor>(); var results = context.Results.Cast<ControllerActionDescriptor>();
@ -104,7 +102,7 @@ namespace System.Web.Http
// Act // Act
var context = new ActionDescriptorProviderContext(); var context = new ActionDescriptorProviderContext();
provider.Invoke(context); Invoke(provider, context);
var results = context.Results.Cast<ControllerActionDescriptor>(); var results = context.Results.Cast<ControllerActionDescriptor>();
@ -140,7 +138,7 @@ namespace System.Web.Http
// Act // Act
var context = new ActionDescriptorProviderContext(); var context = new ActionDescriptorProviderContext();
provider.Invoke(context); Invoke(provider, context);
var results = context.Results.Cast<ControllerActionDescriptor>(); var results = context.Results.Cast<ControllerActionDescriptor>();
@ -177,7 +175,7 @@ namespace System.Web.Http
// Act // Act
var context = new ActionDescriptorProviderContext(); var context = new ActionDescriptorProviderContext();
provider.Invoke(context); Invoke(provider, context);
var results = context.Results.Cast<ControllerActionDescriptor>(); var results = context.Results.Cast<ControllerActionDescriptor>();
@ -213,7 +211,7 @@ namespace System.Web.Http
// Act // Act
var context = new ActionDescriptorProviderContext(); var context = new ActionDescriptorProviderContext();
provider.Invoke(context); Invoke(provider, context);
var results = context.Results.Cast<ControllerActionDescriptor>(); var results = context.Results.Cast<ControllerActionDescriptor>();
@ -238,7 +236,7 @@ namespace System.Web.Http
// Act // Act
var context = new ActionDescriptorProviderContext(); var context = new ActionDescriptorProviderContext();
provider.Invoke(context); Invoke(provider, context);
var results = context.Results.Cast<ControllerActionDescriptor>(); var results = context.Results.Cast<ControllerActionDescriptor>();
@ -263,7 +261,7 @@ namespace System.Web.Http
// Act // Act
var context = new ActionDescriptorProviderContext(); var context = new ActionDescriptorProviderContext();
provider.Invoke(context); Invoke(provider, context);
var results = context.Results.Cast<ControllerActionDescriptor>(); var results = context.Results.Cast<ControllerActionDescriptor>();
@ -291,7 +289,7 @@ namespace System.Web.Http
// Act // Act
var context = new ActionDescriptorProviderContext(); var context = new ActionDescriptorProviderContext();
provider.Invoke(context); Invoke(provider, context);
var results = context.Results.Cast<ControllerActionDescriptor>(); var results = context.Results.Cast<ControllerActionDescriptor>();
@ -318,7 +316,7 @@ namespace System.Web.Http
// Act // Act
var context = new ActionDescriptorProviderContext(); var context = new ActionDescriptorProviderContext();
provider.Invoke(context); Invoke(provider, context);
var results = context.Results.Cast<ControllerActionDescriptor>(); var results = context.Results.Cast<ControllerActionDescriptor>();
@ -347,7 +345,7 @@ namespace System.Web.Http
// Act // Act
var context = new ActionDescriptorProviderContext(); var context = new ActionDescriptorProviderContext();
provider.Invoke(context); Invoke(provider, context);
var results = context.Results.Cast<ControllerActionDescriptor>(); 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(); var assemblyProvider = new FixedSetAssemblyProvider();
assemblyProvider.CandidateAssemblies.Add(GetType().GetTypeInfo().Assembly); assemblyProvider.CandidateAssemblies.Add(GetType().GetTypeInfo().Assembly);
@ -398,11 +396,13 @@ namespace System.Web.Http
optionsAccessor.Object, optionsAccessor.Object,
new NullLoggerFactory()); new NullLoggerFactory());
return new NestedProviderManager<ActionDescriptorProviderContext>( return provider;
new INestedProvider<ActionDescriptorProviderContext>[] }
{
provider private void Invoke(ControllerActionDescriptorProvider provider, ActionDescriptorProviderContext context)
}); {
provider.OnProvidersExecuting(context);
provider.OnProvidersExecuted(context);
} }
private class NamespaceFilteredControllerTypeProvider : DefaultControllerTypeProvider private class NamespaceFilteredControllerTypeProvider : DefaultControllerTypeProvider

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Threading; using System.Threading;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Core;
namespace BasicWebSite 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) if (context.Results.Count == 0)
{ {
throw new InvalidOperationException("No actions found!"); throw new InvalidOperationException("No actions found!");

View File

@ -1,9 +1,11 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // 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. // 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.Globalization;
using System.Linq;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.Framework.DependencyInjection; using Microsoft.AspNet.Mvc.Core;
namespace BasicWebSite namespace BasicWebSite
{ {
@ -11,9 +13,9 @@ namespace BasicWebSite
{ {
private readonly ActionDescriptorCreationCounter _counterService; 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() public IActionResult CountActionDescriptorInvocations()

View File

@ -3,6 +3,7 @@
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace BasicWebSite namespace BasicWebSite
@ -19,7 +20,7 @@ namespace BasicWebSite
// Add MVC services to the services container // Add MVC services to the services container
services.AddMvc(configuration); services.AddMvc(configuration);
services.AddSingleton<INestedProvider<ActionDescriptorProviderContext>, ActionDescriptorCreationCounter>(); services.AddSingleton<IActionDescriptorProvider, ActionDescriptorCreationCounter>();
services.ConfigureMvcOptions(options => services.ConfigureMvcOptions(options =>
{ {

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
namespace RequestServicesWebSite namespace RequestServicesWebSite

View File

@ -3,6 +3,7 @@
using System; using System;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ActionConstraints;
namespace VersioningWebSite namespace VersioningWebSite
{ {

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ActionConstraints;
namespace VersioningWebSite namespace VersioningWebSite
{ {