Changes in WebFx for compatibility with routing

This commit is contained in:
Ryan Nowak 2014-03-05 17:17:12 -08:00
parent 914d8e8a3b
commit 905e84ab0a
3 changed files with 44 additions and 38 deletions

View File

@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;

using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.ConfigurationModel;
using Microsoft.AspNet.DependencyInjection;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Routing.Owin;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Routing.Template;
using Microsoft.Net.Runtime;
@ -25,14 +23,20 @@ namespace MvcSample.Web
var configuration = new Configuration();
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);
router.Routes.Add(new TemplateRoute(
endpoint,
routes.MapRoute(
"{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);
}
}
}
}

View File

@ -1,12 +1,10 @@
#if NET45
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.ConfigurationModel;
using Microsoft.AspNet.DependencyInjection;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Routing.Owin;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Routing.Template;
using Microsoft.Net.Runtime;
using Owin;
@ -39,20 +37,21 @@ namespace MvcSample
var services = MvcServices.GetDefaultServices(configuration, _env);
var serviceProvider = new ServiceProvider().Add(services);
var router = builder.UseRouter();
var routes = new RouteCollection()
{
DefaultHandler = new MvcApplication(serviceProvider),
};
var endpoint = ActivatorUtilities.CreateInstance<RouteEndpoint>(serviceProvider);
router.Routes.Add(new TemplateRoute(
endpoint,
"{controller}",
new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "controller", "Home" } }));
router.Routes.Add(new TemplateRoute(
endpoint,
routes.MapRoute(
"{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

View File

@ -1,13 +1,12 @@

using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.DependencyInjection;
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 IActionInvokerFactory _actionInvokerFactory;
@ -15,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.Routing
// Using service provider here to prevent ordering issues with configuration...
// IE: creating routes before configuring services, vice-versa.
public RouteEndpoint(IServiceProvider services)
public MvcApplication(IServiceProvider 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>();
var requestContext = new RequestContext(context, routeValues.Values);
// For now just allow any values to target this application.
context.IsBound = true;
}
public async Task RouteAsync(RouteContext context)
{
var requestContext = new RequestContext(context.HttpContext, context.Values);
var actionDescriptor = await ActionSelector.SelectAsync(requestContext);
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)
{
var ex = new InvalidOperationException("Could not instantiate invoker for the actionDescriptor");
@ -72,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.Routing
await invoker.InvokeActionAsync();
return true;
context.IsHandled = true;
}
}
}