Strathweb TypedRouting AspNetCore 1.1.0 released!

ยท 284 words ยท 2 minutes to read

Today I have released the 1.1.0 version of Typed Routing project. I encourage you to try this if you like to have your routes centrally configured, rather than stored in attributes at action level.

You can install it from NuGet using the Strathweb.TypedRouting.AspNetCore package name. Here is whatโ€™s new in this release.

Filter support ๐Ÿ”—

You can now directly attach filters to your route definitions - filters that should be executed for a given route. This is equivalent to defining a controller action, and annotating it with a relevant attribute such as action filter or authorization filter.

services.AddMvc(opt =>
{
    opt.Get("api/items", c => c.Action<ItemsController>(x => x.Get())).
        WithFilters(new AnnotationFilter(), new TimerFilter());
}).EnableTypedRouting();

Filters can also be resolved from ASP.NET Core DI system - as long as they are registered there before.

services.AddSingleton<TimerFilter>();

services.AddMvc(opt =>
{
    opt.Get("api/items", c => c.Action<ItemsController>(x => x.Get())).
        WithFilter<TimerFilter>();
}).EnableTypedRouting();

Authorization Policy support ๐Ÿ”—

The route definitions can also have ASP.NET Core authorization policies attached to them. For example, you can pass in a policy instance:

services.AddMvc(opt =>
{
    opt.Get("api/secure", c => c.Action<OtherController>(x => x.Foo()).
        WithAuthorizationPolicy(new AuthorizationPolicyBuilder().
            RequireAuthenticatedUser().Build()
        ));
}).EnableTypedRouting();

You can also define a policy as string - then a corresponding policy must be previously registerd in ASP.NET Core DI system.

services.AddAuthorization(o =>
{
    o.AddPolicy("MyPolicy", b => b.RequireAuthenticatedUser());
});

services.AddMvc(opt =>
{
    opt.Get("api/secure", c => c.Action<OtherController>(x => x.Foo()).
        WithAuthorizationPolicy("MyPolicy"));
}).EnableTypedRouting();

New EnableTypedRouting method ๐Ÿ”—

In the past typed routing was enabled by calling an extension method on MvcOptions. This is now obsolete, please use the extension method available on IMvcCoreBuilder and IMvcBuilder. The new filters feature, that reaches into the DI requires that.

If you are interested in helping out, need more information or have any comments, please come to the Gihub repo. Thanks!

About


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