TypedRouting for ASP.NET Core MVC 2

Β· 291 words Β· 2 minutes to read

Today I have released a new version of Strathweb.TypedRouting.AspNetCore. This new version is built as .NET Standard 2.0, and - obviously - finally supports ASP.NET Core MVC 2.

Here is a short summary and some links to help you get started.

Background πŸ”—

As I’ve already blogged here and here, so if you are interested in a more detailed explanation, I recommend checking out these articles. However, in short, Strathweb.TypedRouting.AspNetCore allows you to configure routes in your ASP.NET Core MVC applications using centralized, strongly-typed manner. This is in stark contrast to the two built in approaches of the framework: routing via attributes, or centralized routing without strong typing.

TypedRouting existed for ASP.NET Web API and was then migrated to ASP.NET Core MVC.

TypedRouting in ASP.NET Core MVC 2 πŸ”—

Fundamentally, the ASP.NET Core MVC 2 version works the same way as the previous one, however, it contains a simplified and cleaner configuration/surface API. It is now only available on IMvcBuilder/IMvcCoreBuilder extension, and is decoupled from MvcOptions.

In your Startup class, after adding MVC, simply call AddTypedRouting(). The routes are configured using an options delegate. An example is shown below:

services.AddMvc().AddTypedRouting(opt =>
    opt.Get("homepage", c => c.Action<HomeController>(x => x.Index()));
    opt.Get("aboutpage/{name}", c => c.Action<HomeController>(x => x.About(Param<string>.Any)));
    opt.Post("sendcontact", c => c.Action<HomeController>(x => x.Contact()));

In addition to that, several painful bugs have been fixed - the main one is that the library now supports integration testing using the TestHost infrastructure, as it no longer persists static state.

I encourage you to give the library a try, it can be installed from Nuget, using the Nuget client:

nuget install Strathweb.TypedRouting.AspNetCore

or via the .NET Core CLI:

dotnet add package Strathweb.TypedRouting.AspNetCore

In case you have any issues, or would like to help out, please visit the Github repo.


Hi! I'm Filip W., a cloud architect from ZΓΌrich πŸ‡¨πŸ‡­. I like Toronto Maple Leafs πŸ‡¨πŸ‡¦, Rancid and quantum computing. Oh, and I love the Lowlands 🏴󠁧󠁒󠁳󠁣󠁴󠁿.

You can find me on Github and on Mastodon.

My Introduction to Quantum Computing with Q# and QDK book
Microsoft MVP