Use INestedProvider for ADP and AIP
This commit is contained in:
parent
d920003194
commit
803f447686
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.AspNet.DependencyInjection;
|
||||
using Microsoft.AspNet.DependencyInjection.NestedProviders;
|
||||
using Microsoft.AspNet.FileSystems;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Mvc.Razor;
|
||||
|
|
@ -19,14 +20,11 @@ namespace Microsoft.AspNet.Mvc.Startup
|
|||
Add<IActionInvokerFactory, ActionInvokerFactory>();
|
||||
Add<IActionResultHelper, ActionResultHelper>();
|
||||
Add<IActionResultFactory, ActionResultFactory>();
|
||||
Add<IActionDescriptorProvider, TypeMethodBasedActionDescriptorProvider>();
|
||||
Add<IParameterDescriptorFactory, DefaultParameterDescriptorFactory>();
|
||||
Add<IValueProviderFactory, RouteValueValueProviderFactory>();
|
||||
Add<IValueProviderFactory, QueryStringValueProviderFactory>();
|
||||
Add<IActionInvokerProvider, ActionInvokerProvider>();
|
||||
Add<IControllerAssemblyProvider, AppDomainControllerAssemblyProvider>();
|
||||
Add<IActionDiscoveryConventions, DefaultActionDiscoveryConventions>();
|
||||
|
||||
AddInstance<IFileSystem>(new PhysicalFileSystem(appRoot));
|
||||
AddInstance<IMvcRazorHost>(new MvcRazorHost(typeof(RazorView).FullName));
|
||||
|
||||
|
|
@ -36,6 +34,12 @@ namespace Microsoft.AspNet.Mvc.Startup
|
|||
Add<IRazorCompilationService, RazorCompilationService>();
|
||||
Add<IVirtualPathViewFactory, VirtualPathViewFactory>();
|
||||
Add<IViewEngine, RazorViewEngine>();
|
||||
|
||||
// This is temporary until DI has some magic for it
|
||||
Add<INestedProviderManager<ActionDescriptorProviderContext>, NestedProviderManager<ActionDescriptorProviderContext>>();
|
||||
Add<INestedProviderManager<ActionInvokerProviderContext>, NestedProviderManager<ActionInvokerProviderContext>>();
|
||||
Add<INestedProvider<ActionDescriptorProviderContext>, TypeMethodBasedActionDescriptorProvider>();
|
||||
Add<INestedProvider<ActionInvokerProviderContext>, ActionInvokerProvider>();
|
||||
}
|
||||
|
||||
private void Add<T, TU>() where TU : T
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public class ActionDescriptorProviderContext
|
||||
{
|
||||
public ActionDescriptorProviderContext()
|
||||
{
|
||||
ActionDescriptors = new List<ActionDescriptor>();
|
||||
}
|
||||
|
||||
public List<ActionDescriptor> ActionDescriptors { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +1,21 @@
|
|||
namespace Microsoft.AspNet.Mvc
|
||||
using Microsoft.AspNet.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public class ActionInvokerFactory : IActionInvokerFactory
|
||||
{
|
||||
private readonly IActionResultFactory _actionResultFactory;
|
||||
private readonly IActionInvokerProvider _actionInvokerProvider;
|
||||
private readonly IActionDescriptorProvider _routeContextProvider;
|
||||
private readonly INestedProviderManager<ActionInvokerProviderContext> _actionInvokerProvider;
|
||||
|
||||
public ActionInvokerFactory(IActionResultFactory actionResultFactory,
|
||||
IActionDescriptorProvider actionDescriptorProvider,
|
||||
IActionInvokerProvider actionInvokerProvider)
|
||||
public ActionInvokerFactory(INestedProviderManager<ActionInvokerProviderContext> actionInvokerProvider)
|
||||
{
|
||||
_actionResultFactory = actionResultFactory;
|
||||
_routeContextProvider = actionDescriptorProvider;
|
||||
_actionInvokerProvider = actionInvokerProvider;
|
||||
}
|
||||
|
||||
public IActionInvoker CreateInvoker(ActionContext actionContext)
|
||||
{
|
||||
return _actionInvokerProvider.GetInvoker(actionContext);
|
||||
var context = new ActionInvokerProviderContext(actionContext);
|
||||
_actionInvokerProvider.Invoke(context);
|
||||
return context.ActionInvoker;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,21 +17,28 @@ namespace Microsoft.AspNet.Mvc
|
|||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public IActionInvoker GetInvoker(ActionContext actionContext)
|
||||
public int Order
|
||||
{
|
||||
var ad = actionContext.ActionDescriptor as TypeMethodBasedActionDescriptor;
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public void Invoke(ActionInvokerProviderContext context, Action callNext)
|
||||
{
|
||||
var ad = context.ActionContext.ActionDescriptor as TypeMethodBasedActionDescriptor;
|
||||
|
||||
if (ad != null)
|
||||
{
|
||||
return new TypeMethodBasedActionInvoker(
|
||||
actionContext,
|
||||
context.ActionInvoker = new TypeMethodBasedActionInvoker(
|
||||
context.ActionContext,
|
||||
ad,
|
||||
_actionResultFactory,
|
||||
_controllerFactory,
|
||||
_serviceProvider);
|
||||
}
|
||||
|
||||
return null;
|
||||
callNext();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public class ActionInvokerProviderContext
|
||||
{
|
||||
public ActionInvokerProviderContext(ActionContext actionContext)
|
||||
{
|
||||
if (actionContext == null)
|
||||
{
|
||||
throw new ArgumentNullException("actionContext");
|
||||
}
|
||||
|
||||
ActionContext = actionContext;
|
||||
}
|
||||
|
||||
public ActionContext ActionContext { get; private set; }
|
||||
|
||||
public IActionInvoker ActionInvoker { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -2,18 +2,21 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.DependencyInjection;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public class DefaultActionSelector : IActionSelector
|
||||
{
|
||||
private readonly IEnumerable<IActionDescriptorProvider> _actionDescriptorProviders;
|
||||
private readonly INestedProviderManager<ActionDescriptorProviderContext> _actionDescriptorProvider;
|
||||
private readonly IEnumerable<IValueProviderFactory> _valueProviderFactory;
|
||||
|
||||
public DefaultActionSelector(IEnumerable<IActionDescriptorProvider> actionDescriptorProviders, IEnumerable<IValueProviderFactory> valueProviderFactories)
|
||||
public DefaultActionSelector(
|
||||
INestedProviderManager<ActionDescriptorProviderContext> actionDescriptorProvider,
|
||||
IEnumerable<IValueProviderFactory> valueProviderFactories)
|
||||
{
|
||||
_actionDescriptorProviders = actionDescriptorProviders;
|
||||
_actionDescriptorProvider = actionDescriptorProvider;
|
||||
_valueProviderFactory = valueProviderFactories;
|
||||
}
|
||||
|
||||
|
|
@ -24,7 +27,10 @@ namespace Microsoft.AspNet.Mvc
|
|||
throw new ArgumentNullException("context");
|
||||
}
|
||||
|
||||
var allDescriptors = _actionDescriptorProviders.SelectMany(d => d.GetDescriptors());
|
||||
var actionDescriptorProviderContext = new ActionDescriptorProviderContext();
|
||||
_actionDescriptorProvider.Invoke(actionDescriptorProviderContext);
|
||||
|
||||
var allDescriptors = actionDescriptorProviderContext.Results;
|
||||
|
||||
var matching = allDescriptors.Where(ad => Match(ad, context)).ToList();
|
||||
if (matching.Count == 0)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
using Microsoft.AspNet.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public interface IActionDescriptorProvider
|
||||
public interface IActionDescriptorProvider : INestedProvider<ActionDescriptorProviderContext>
|
||||
{
|
||||
IEnumerable<ActionDescriptor> GetDescriptors();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
namespace Microsoft.AspNet.Mvc
|
||||
using Microsoft.AspNet.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public interface IActionInvokerProvider
|
||||
public interface IActionInvokerProvider : INestedProvider<ActionInvokerProviderContext>
|
||||
{
|
||||
IActionInvoker GetInvoker(ActionContext actionContext);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
|
|
@ -22,6 +23,17 @@ namespace Microsoft.AspNet.Mvc
|
|||
_parameterDescriptorFactory = parameterDescriptorFactory;
|
||||
}
|
||||
|
||||
public int Order
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public void Invoke(ActionDescriptorProviderContext context, Action callNext)
|
||||
{
|
||||
context.ActionDescriptors.AddRange(GetDescriptors());
|
||||
callNext();
|
||||
}
|
||||
|
||||
public IEnumerable<ActionDescriptor> GetDescriptors()
|
||||
{
|
||||
var assemblies = _controllerAssemblyProvider.Assemblies;
|
||||
|
|
@ -84,26 +96,5 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
return ad;
|
||||
}
|
||||
|
||||
private static void ApplyRest(TypeMethodBasedActionDescriptor descriptor, IEnumerable<string> httpMethods)
|
||||
{
|
||||
|
||||
descriptor.RouteConstraints.Add(new RouteDataActionConstraint("action", RouteKeyHandling.DenyKey));
|
||||
}
|
||||
|
||||
private static void ApplyRpc(TypeMethodBasedActionDescriptor descriptor, ActionInfo convention)
|
||||
{
|
||||
|
||||
var methods = convention.HttpMethods;
|
||||
|
||||
// rest action require specific methods, but RPC actions do not.
|
||||
if (methods != null)
|
||||
{
|
||||
descriptor.MethodConstraints = new List<HttpMethodConstraint>
|
||||
{
|
||||
new HttpMethodConstraint(methods)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue