Added UseMvc extension method via IBuilder extensions.
This commit is contained in:
parent
b8eb16d98d
commit
73e1386724
|
|
@ -1,6 +1,4 @@
|
|||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.DependencyInjection;
|
||||
using Microsoft.AspNet.DependencyInjection.Fallback;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.RequestContainer;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
|
@ -9,32 +7,27 @@ namespace MvcSample.Web
|
|||
{
|
||||
public class Startup
|
||||
{
|
||||
public void Configuration(IBuilder builder)
|
||||
public void Configuration(IBuilder app)
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddMvc();
|
||||
services.AddSingleton<PassThroughAttribute, PassThroughAttribute>();
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider(builder.ServiceProvider);
|
||||
|
||||
var routes = new RouteCollection()
|
||||
app.UseContainer(services =>
|
||||
{
|
||||
DefaultHandler = new MvcRouteHandler(),
|
||||
};
|
||||
services.AddMvc();
|
||||
services.AddSingleton<PassThroughAttribute, PassThroughAttribute>();
|
||||
});
|
||||
|
||||
// TODO: Add support for route constraints, so we can potentially constrain by existing routes
|
||||
routes.MapRoute("{area}/{controller}/{action}");
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
// TODO: Add support for route constraints, so we can potentially constrain by existing routes
|
||||
routes.MapRoute("{area}/{controller}/{action}");
|
||||
|
||||
routes.MapRoute(
|
||||
"{controller}/{action}",
|
||||
new { controller = "Home", action = "Index" });
|
||||
routes.MapRoute(
|
||||
"{controller}/{action}",
|
||||
new { controller = "Home", action = "Index" });
|
||||
|
||||
routes.MapRoute(
|
||||
"{controller}",
|
||||
new { controller = "Home" });
|
||||
|
||||
builder.UseContainer(serviceProvider);
|
||||
builder.UseRouter(routes);
|
||||
routes.MapRoute(
|
||||
"{controller}",
|
||||
new { controller = "Home" });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public static class BuilderExtensions
|
||||
{
|
||||
public static IBuilder UseMvc(this IBuilder app, Action<IRouteCollection> configureRoutes)
|
||||
{
|
||||
var routes = new RouteCollection
|
||||
{
|
||||
DefaultHandler = new MvcRouteHandler()
|
||||
};
|
||||
|
||||
// REVIEW: Consider adding UseMvc() that automagically adds the default MVC route
|
||||
configureRoutes(routes);
|
||||
|
||||
return app.UseRouter(routes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@
|
|||
<Content Include="Project.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BuilderExtensions.cs" />
|
||||
<Compile Include="ServiceCollectionExtensions.cs" />
|
||||
<Compile Include="MvcServices.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in New Issue