Phema.Routing 3.0.5

dotnet add package Phema.Routing --version 3.0.5
NuGet\Install-Package Phema.Routing -Version 3.0.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Phema.Routing" Version="3.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Phema.Routing --version 3.0.5
#r "nuget: Phema.Routing, 3.0.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Phema.Routing as a Cake Addin
#addin nuget:?package=Phema.Routing&version=3.0.5

// Install Phema.Routing as a Cake Tool
#tool nuget:?package=Phema.Routing&version=3.0.5

Phema.Routing

Build Status Nuget Nuget

C# strongly typed routing library for ASP.NET Core built on top of MVC Model conventions with built-in From.*, ApiExplorer, Authorization and Caching support

Installation

$> dotnet add package Phema.Routing

Features

  • Strongly typed url generation
  • BindingSources selection e.g. From.Body, From.Route, From.From
  • Named parameters override e.g. From.Query<int>("query"), From.Route<string>("route") /{route}?query=12345
  • Flexible constraint and filter configuration
  • Extension methods for authorization, caching, api documentation, etc

Usage

// Startup
services.AddControllers() // `.AddMvc()`, `.AddMvcCore()`
  .AddRouting(routing =>
  {
    // Simple route
    routing.AddController<OrdersController>("orders", controller =>
      controller.AddRoute("dashboard", c => c.Dashboard())
        .HttpGet());

    // Authorize controller with "id" parameter from query
    routing.AddController<TaskController>("tasks", controller =>
      controller.AddRoute("edit/{id}", c => c.Edit(From.Route<int>("id"))) // `From.*` is matches `[From*]` attributes
        .HttpGet()
        .Authorize());

    // Multiple routes in one controller
    routing.AddController<WashingController>("washing", controller =>
    {
      // Override controller `.Authorize()`
      controller.AddRoute("wash", c => c.Wash(From.Query<int>())) // If name not specified - used method parameter name
        .HttpGet()
        .AllowAnonymous()

      // Inherit authorization requirement from controller
      controller.AddRoute("dry", c => c.Dry(From.Body<DryModel>()))
        .HttpPost()
        .ValidateAntiForgeryToken();
    }).Authorize();

    // Multiple binding sources
    routing.AddController<MoviesController>("movies", controller =>
      controller.AddRoute("{category}/upload", c =>
        c.Upload(From.Route<string>(), From.Body<UploadMovieModel>(), From.Query<bool>("compress")))
        .HttpPost());
  });

Action url generation (IUrlHelper used)

// From.Query with parameter override
services.AddRouting(routing =>
  routing.AddController<Controller>("controller", controller =>
    controller.AddRoute("action", c => c.Action(From.Query<int>("parameter")))));

// "controller/action?parameter=10"
var action = Url.Action<Controller>(c => c.Action(10));

// From.Route with route part override
services.AddRouting(routing =>
  routing.AddController<Controller>("controller", controller =>
    controller.AddRoute("action/{mode}", c => c.Route(From.Route<Mode>("mode")))));

// "controller/action/access"
var action = Url.Action<Controller>(c => c.Action("access"));

// Combine query and route parts
services.AddRouting(routing =>
  routing.AddController<Controller>("controller", controller =>
    controller.AddRoute("action/{mode}", c => c.Route(From.Query<int>(), From.Route<Mode>()))));

// "controller/action/access?parameter=10"
var action = Url.Action<Controller>(c => c.Action(10, "access"));

// Get values from current request using From.Query in IUrlHelper generation
services.AddRouting(routing =>
  routing.AddController<Controller>("controller", controller =>
    controller.AddRoute("action", c => c.Action(From.Query<int>()))));

// P.S. BindingSources not used in url will ignored (e.g. `From.Body<TModel>()` used only for compile reasons)
// "controller/action?parameter=VALUE_FROM_CURRENT_REQUEST"
var action = Url.Action<Controller>(c => c.Action(From.Query<int>()));

Extensions

  • Http methods - .HttpPost(), .HttpGet()...
  • Caching - .Cached(...)
  • Authorization - .Authorize(...), .AllowAnonymous()
  • AntiForgeryToken - .ValidateAntiForgeryToken(), .IgnoreAntiforgeryToken()
  • Https - .RequireHttps()
  • RequestSizeLimit - .RequestSizeLimit(...), .DisableRequestSizeLimit()
  • Produces, Consumes for ApiExplorer - .Produces<TModel>(...), .Consumes(...)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 is compatible.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.5 1,120 9/25/2019
3.0.4 995 8/27/2019
3.0.3 1,177 7/27/2019
3.0.2 1,122 7/26/2019
3.0.1 1,123 7/25/2019
3.0.0 983 7/19/2019