Handling routes in .NET Core

As we just saw, the new routing implementation is basically handled by the two services.AddMvc() and app.UseMvc() methods called within the Startup.cs file, which perform the following tasks respectively:

  • Registering MVC using the Dependency Injection framework built into ASP.NET Core
  • Adding the required middleware to the HTTP request pipeline, while also (optionally) setting a pack of default routes

We can take a look at what happens under the hood by looking at the current implementation of the app.UseMvc() method in the framework code (relevant lines are highlighted):

 public static IApplicationBuilder UseMvc(     [NotNull] this IApplicationBuilder app,     [NotNull] Action<IRouteBuilder> configureRoutes) {  // ...

Get ASP.NET Core 2 and Angular 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.