Changes in WebFx for compatibility with routing
This commit is contained in:
parent
914d8e8a3b
commit
905e84ab0a
|
|
@ -1,11 +1,9 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.AspNet.Abstractions;
|
using Microsoft.AspNet.Abstractions;
|
||||||
using Microsoft.AspNet.ConfigurationModel;
|
using Microsoft.AspNet.ConfigurationModel;
|
||||||
using Microsoft.AspNet.DependencyInjection;
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
using Microsoft.AspNet.Mvc;
|
using Microsoft.AspNet.Mvc;
|
||||||
using Microsoft.AspNet.Mvc.Routing;
|
using Microsoft.AspNet.Routing;
|
||||||
using Microsoft.AspNet.Routing.Owin;
|
|
||||||
using Microsoft.AspNet.Routing.Template;
|
using Microsoft.AspNet.Routing.Template;
|
||||||
using Microsoft.Net.Runtime;
|
using Microsoft.Net.Runtime;
|
||||||
|
|
||||||
|
|
@ -25,14 +23,20 @@ namespace MvcSample.Web
|
||||||
var configuration = new Configuration();
|
var configuration = new Configuration();
|
||||||
var serviceProvider = new ServiceProvider().Add(MvcServices.GetDefaultServices(configuration, _env));
|
var serviceProvider = new ServiceProvider().Add(MvcServices.GetDefaultServices(configuration, _env));
|
||||||
|
|
||||||
var router = app.UseRouter();
|
var routes = new RouteCollection()
|
||||||
|
{
|
||||||
|
DefaultHandler = new MvcApplication(serviceProvider),
|
||||||
|
};
|
||||||
|
|
||||||
var endpoint = ActivatorUtilities.CreateInstance<RouteEndpoint>(serviceProvider);
|
routes.MapRoute(
|
||||||
|
|
||||||
router.Routes.Add(new TemplateRoute(
|
|
||||||
endpoint,
|
|
||||||
"{controller}/{action}",
|
"{controller}/{action}",
|
||||||
new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "controller", "Home" }, { "action", "Index" } }));
|
new { controller = "Home", action = "Index" });
|
||||||
|
|
||||||
|
routes.MapRoute(
|
||||||
|
"{controller}",
|
||||||
|
new { controller = "Home" });
|
||||||
|
|
||||||
|
app.UseRouter(routes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
#if NET45
|
#if NET45
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.AspNet.Abstractions;
|
using Microsoft.AspNet.Abstractions;
|
||||||
using Microsoft.AspNet.ConfigurationModel;
|
using Microsoft.AspNet.ConfigurationModel;
|
||||||
using Microsoft.AspNet.DependencyInjection;
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
using Microsoft.AspNet.Mvc;
|
using Microsoft.AspNet.Mvc;
|
||||||
using Microsoft.AspNet.Mvc.Routing;
|
using Microsoft.AspNet.Routing;
|
||||||
using Microsoft.AspNet.Routing.Owin;
|
|
||||||
using Microsoft.AspNet.Routing.Template;
|
using Microsoft.AspNet.Routing.Template;
|
||||||
using Microsoft.Net.Runtime;
|
using Microsoft.Net.Runtime;
|
||||||
using Owin;
|
using Owin;
|
||||||
|
|
@ -39,20 +37,21 @@ namespace MvcSample
|
||||||
var services = MvcServices.GetDefaultServices(configuration, _env);
|
var services = MvcServices.GetDefaultServices(configuration, _env);
|
||||||
var serviceProvider = new ServiceProvider().Add(services);
|
var serviceProvider = new ServiceProvider().Add(services);
|
||||||
|
|
||||||
var router = builder.UseRouter();
|
var routes = new RouteCollection()
|
||||||
|
{
|
||||||
|
DefaultHandler = new MvcApplication(serviceProvider),
|
||||||
|
};
|
||||||
|
|
||||||
var endpoint = ActivatorUtilities.CreateInstance<RouteEndpoint>(serviceProvider);
|
routes.MapRoute(
|
||||||
|
|
||||||
router.Routes.Add(new TemplateRoute(
|
|
||||||
endpoint,
|
|
||||||
"{controller}",
|
|
||||||
new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "controller", "Home" } }));
|
|
||||||
|
|
||||||
router.Routes.Add(new TemplateRoute(
|
|
||||||
endpoint,
|
|
||||||
"{controller}/{action}",
|
"{controller}/{action}",
|
||||||
new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "controller", "Home" }, { "action", "Index" } }));
|
new { controller = "Home", action = "Index" });
|
||||||
|
|
||||||
|
routes.MapRoute(
|
||||||
|
"{controller}",
|
||||||
|
new { controller = "Home" });
|
||||||
|
|
||||||
|
builder.UseRouter(routes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Abstractions;
|
|
||||||
using Microsoft.AspNet.DependencyInjection;
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
using Microsoft.AspNet.Routing;
|
using Microsoft.AspNet.Routing;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Routing
|
namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
public class RouteEndpoint : IRouteEndpoint
|
public class MvcApplication : IRouter
|
||||||
{
|
{
|
||||||
private readonly IServiceProvider _services;
|
private readonly IServiceProvider _services;
|
||||||
private IActionInvokerFactory _actionInvokerFactory;
|
private IActionInvokerFactory _actionInvokerFactory;
|
||||||
|
|
@ -15,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.Routing
|
||||||
|
|
||||||
// Using service provider here to prevent ordering issues with configuration...
|
// Using service provider here to prevent ordering issues with configuration...
|
||||||
// IE: creating routes before configuring services, vice-versa.
|
// IE: creating routes before configuring services, vice-versa.
|
||||||
public RouteEndpoint(IServiceProvider services)
|
public MvcApplication(IServiceProvider services)
|
||||||
{
|
{
|
||||||
_services = services;
|
_services = services;
|
||||||
}
|
}
|
||||||
|
|
@ -46,20 +45,24 @@ namespace Microsoft.AspNet.Mvc.Routing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> Send(HttpContext context)
|
public void BindPath(BindPathContext context)
|
||||||
{
|
{
|
||||||
var routeValues = context.GetFeature<IRouteValues>();
|
// For now just allow any values to target this application.
|
||||||
var requestContext = new RequestContext(context, routeValues.Values);
|
context.IsBound = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RouteAsync(RouteContext context)
|
||||||
|
{
|
||||||
|
var requestContext = new RequestContext(context.HttpContext, context.Values);
|
||||||
|
|
||||||
var actionDescriptor = await ActionSelector.SelectAsync(requestContext);
|
var actionDescriptor = await ActionSelector.SelectAsync(requestContext);
|
||||||
|
|
||||||
if (actionDescriptor == null)
|
if (actionDescriptor == null)
|
||||||
{
|
{
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var invoker = ActionInvokerFactory.CreateInvoker(new ActionContext(context, routeValues.Values, actionDescriptor));
|
var actionContext = new ActionContext(context.HttpContext, context.Values, actionDescriptor);
|
||||||
|
var invoker = ActionInvokerFactory.CreateInvoker(actionContext);
|
||||||
if (invoker == null)
|
if (invoker == null)
|
||||||
{
|
{
|
||||||
var ex = new InvalidOperationException("Could not instantiate invoker for the actionDescriptor");
|
var ex = new InvalidOperationException("Could not instantiate invoker for the actionDescriptor");
|
||||||
|
|
@ -72,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.Routing
|
||||||
|
|
||||||
await invoker.InvokeActionAsync();
|
await invoker.InvokeActionAsync();
|
||||||
|
|
||||||
return true;
|
context.IsHandled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue