ZRouting - LayerZero.Tools.Routing (.NET 8+ Routing manager)
ZRouting is a convention-based routing extension for ASP.NET Core (.NET) designed to standardize URL structures using namespace-driven tokens.
It enables modular applications to derive route segments directly from controller namespace structure, reducing repetitive configuration while enforcing architectural consistency.
ZRouting is particularly suited for:
- Modular monoliths
- Layered enterprise applications
- Feature-based architectures
- Versioned APIs
It promotes predictable routing patterns without requiring attribute duplication or extensive per-controller configuration.
1. Overview
ZRouting extends ASP.NET Core routing by introducing configurable route tokens that map to controller namespace segments.
Instead of manually defining routes or repeating attributes across controllers, route values can be inferred from structural conventions defined once during startup.
This approach ensures:
- Consistency between namespace structure and URL topology
- Centralized routing configuration
- Reduced boilerplate
- Architectural transparency
2. Features Overview
2.1 Convention-Based Route Composition
ZRouting introduces configurable route tokens that are resolved from namespace segments and injected into a route template.
Example configuration:
builder.AddZRouting(cfg =>
{
cfg.Tokens = new List<ZRouteToken>
{
new ZRouteToken { NameSpaceIndex = 5, DefaultValue = "0_0", Name = "version" },
new ZRouteToken { NameSpaceIndex = 6, DefaultValue = "unknown", Name = "feature" },
new ZRouteToken { NameSpaceIndex = 4, DefaultValue = "unknown", Name = "area" }
};
cfg.RouteTemplate = "[area]/v[version]/[feature]/[controller]/[action]";
});
The above configuration is only a sample. Token names, namespace indexes, and route templates are fully customizable.
2.2 Flexible Token System
Each token consists of:
- Name – Identifier used inside the route template
- NameSpaceIndex – Namespace segment position
- DefaultValue – Fallback if the namespace segment is unavailable
This enables:
- Namespace-based version extraction
- Feature-based routing segmentation
- Domain grouping
- Custom architectural mapping strategies
2.3 Startup-Time Resolution
Route token resolution occurs during application startup.
This ensures:
- No per-request reflection overhead
- Deterministic route generation
- Predictable behavior across environments
3. Component Index (Feature Modules)
ZRouting integrates naturally with feature-oriented module structures.
3.1 Example Namespace Structure
Company.Product.Area.V1_0.Feature.Controllers
With appropriate token configuration, this may map to:
/{area}/v{version}/{feature}/{controller}/{action}
The mapping behavior is entirely driven by configured tokens.
4. Design Goals
- Convention over repetition
- Architectural transparency
- Customizable token system
- Low runtime overhead
- Minimal intrusion into existing ASP.NET Core routing configuration