diff --git a/samples/MvcSample.Web/Startup.cs b/samples/MvcSample.Web/Startup.cs index 2a02529425..2a4a4608da 100644 --- a/samples/MvcSample.Web/Startup.cs +++ b/samples/MvcSample.Web/Startup.cs @@ -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(); - - var serviceProvider = services.BuildServiceProvider(builder.ServiceProvider); - - var routes = new RouteCollection() + app.UseContainer(services => { - DefaultHandler = new MvcRouteHandler(), - }; + services.AddMvc(); + services.AddSingleton(); + }); - // 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" }); + }); } } } diff --git a/src/Microsoft.AspNet.Mvc/BuilderExtensions.cs b/src/Microsoft.AspNet.Mvc/BuilderExtensions.cs new file mode 100644 index 0000000000..d66949f2bf --- /dev/null +++ b/src/Microsoft.AspNet.Mvc/BuilderExtensions.cs @@ -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 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); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc/Microsoft.AspNet.Mvc.kproj b/src/Microsoft.AspNet.Mvc/Microsoft.AspNet.Mvc.kproj index 73f8a18ab1..1f91553241 100644 --- a/src/Microsoft.AspNet.Mvc/Microsoft.AspNet.Mvc.kproj +++ b/src/Microsoft.AspNet.Mvc/Microsoft.AspNet.Mvc.kproj @@ -20,6 +20,7 @@ +