MrBogomips.AspNetMvc.ModuleRouting
0.0.1
dotnet add package MrBogomips.AspNetMvc.ModuleRouting --version 0.0.1
NuGet\Install-Package MrBogomips.AspNetMvc.ModuleRouting -Version 0.0.1
<PackageReference Include="MrBogomips.AspNetMvc.ModuleRouting" Version="0.0.1" />
paket add MrBogomips.AspNetMvc.ModuleRouting --version 0.0.1
#r "nuget: MrBogomips.AspNetMvc.ModuleRouting, 0.0.1"
// Install MrBogomips.AspNetMvc.ModuleRouting as a Cake Addin
#addin nuget:?package=MrBogomips.AspNetMvc.ModuleRouting&version=0.0.1
// Install MrBogomips.AspNetMvc.ModuleRouting as a Cake Tool
#tool nuget:?package=MrBogomips.AspNetMvc.ModuleRouting&version=0.0.1
Motivation
This packages arises from the need to develop a modular Web Api.
Asp.Net Core, by the mean of Application Parts allows you to modularize the code and easily aggregate them within an hosting app.
The support for routing, in cotrast, is a bit too hostic.
Areas give some kind of support but are not mixable with Annotated routing wich is the elective way to define a WebApi routing.
Thi package aims to fill the gap.
Even it express its usefulness at best in conjuction with modularized app development, you can also use it as an alternative way to maintain the routing configuration in a module-fashion style.
Getting Start
Clone, Drop or Nuget this package within your solution.
Nuget Artifacts id: MrBogomips.AspNetMvc.ModuleRouting
.
Startup.cs
Here you map modules to route templates.
using MrBogomips.AspNetMvc.ModuleRouting;
...
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// ...
app.UseMvc(routes =>
{
routes.MapModuleRoute("Sample.MvcModuleA", "moduleA"); // Here's the fun!
routes.MapModuleRoute("Sample.MvcModuleB", "moduleB");
});
}
«Your Modular» Controller.cs
Within your controller you simply decorate it:
using MrBogomips.AspNetMvc.ModuleRouting;
namespace Sample.MvcModuleA
{
[RouteModule("Sample.MvcModuleA")]
public abstract class ModuleBaseController: ControllerBase {}
// BEST Practice: use a common module controller base class
// to achieve a better consistency and manteinability
public class ModuleController: ModuleBaseController
{
[HttpGet("hello")]
public string Hello() => "Hello from module A";
}
}
et voilà…
Suggested Practice...
... for a complex, wide Web Api organization:
- Split your api within separte modules, i.e. Assemblies
- Within each module provide a base
Controller
class decorated with one of theRoutModule
attributes - Aggregate the modules in your host app by
AddAppicationPart(…)
- Configure your modular routing by
MapModuleRoute(…)
For a reference app check out the Sample App of this project.
Product | Versions 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 | netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.0
- Microsoft.AspNetCore.Mvc.Core (>= 2.0.3)
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 |
---|---|---|
0.0.1 | 1,234 | 4/22/2018 |