Overview

AspNetConventions is designed to be a “plug-and-play” solution that integrates seamlessly into the standard ASP.NET Core. By using these extension methods, you activate automatic route transformation, standardized response formatting, and global exception handling across your entire application.

Supported Endpoint Types

The library provides consistent standardization across all primary ASP.NET Core endpoint styles:

Endpoint Type Supported
MVC Controllers
Minimal APIs
Razor Pages

Extension methods

AddAspNetConventions

This method enables conventions for MVC Controllers and Razor Pages. It attaches to the IMvcBuilder to inject global filters and configuration logic.

IMvcBuilder AddAspNetConventions(
    this IMvcBuilder builder,
    Action<AspNetConventionOptions>? configure = null)
Parameter type Description
configure Action<AspNetConventionsOptions>? An optional action to configure conventions via AspNetConventionsOptions object.

UseAspNetConventions

This method enables conventions for Minimal APIs. It returns a RouteGroupBuilder — map your endpoints on the returned group so that response formatting, route transformation, and exception handling are applied to them.

RouteGroupBuilder UseAspNetConventions(
    this WebApplication app,
    string prefix = "",
    Action<AspNetConventionOptions>? configure = null)
Parameter Type Description
app WebApplication The current web application instance.
prefix string An optional route prefix applied to all endpoints registered on the returned group. Defaults to "" (root, no prefix).
configure Action<AspNetConventionsOptions>? An optional action to configure conventions via AspNetConventionsOptions.

Usage:

var api = app.UseAspNetConventions();

api.MapGet("/users", GetUsers);
api.MapPost("/users", CreateUser);

app.Run();

Zero Configuration

AspNetConventions is designed with a “sensible defaults” philosophy. You can automatically achieve consistent standardization across your entire project without writing a single line of configuration code.

The Power of One Line

Turn complex setup into a zero-effort implementation. This is all you need to do:

// All conventions applied with default settings
builder.Services.AddControllers().AddAspNetConventions();

See AspNetConventionsOptions for more info about default settings.