api-setup

Mcafee123's avatarfrom Mcafee123

Configure affolterNET.Web.Api service registration and middleware pipeline. Use when setting up AddApiServices, ConfigureApiApp, or configuring the API middleware order.

⭐0stars🔀0forks📁View on GitHub🕐Updated Jan 8, 2026

When & Why to Use This Skill

The api-setup skill streamlines the configuration of .NET Web API services and middleware pipelines using the affolterNET.Web.Api library. It automates the boilerplate code required for service registration, security header implementation, and middleware orchestration, ensuring a robust and standardized API architecture with minimal manual effort.

Use Cases

  • Rapid API Initialization: Quickly bootstrap new .NET Web API projects by standardizing the service registration and middleware pipeline setup.
  • Security Configuration: Easily enable and manage security headers and authentication modes (None, Authenticate, Authorize) to protect API endpoints.
  • Middleware Pipeline Customization: Precisely inject custom middleware into specific hooks, such as after routing or before endpoint mapping, to handle cross-cutting concerns like logging or multi-tenancy.
  • Environment-Specific Tuning: Seamlessly toggle API configurations and features based on the execution environment (e.g., Development vs. Production) using integrated flags.
nameapi-setup
descriptionConfigure affolterNET.Web.Api service registration and middleware pipeline. Use when setting up AddApiServices, ConfigureApiApp, or configuring the API middleware order.

API Setup

Configure the affolterNET.Web.Api service registration and middleware pipeline.

For complete reference, see Library Guide.

Quick Start

// Program.cs
var builder = WebApplication.CreateBuilder(args);

// Step 1: Register services
var options = builder.Services.AddApiServices(
    builder.Environment.IsDevelopment(),
    builder.Configuration,
    opts => {
        opts.EnableSecurityHeaders = true;
        opts.ConfigureApi = api => {
            api.AuthMode = AuthenticationMode.Authorize;
        };
    });

var app = builder.Build();

// Step 2: Configure middleware
app.ConfigureApiApp(options);

app.Run();

Configuration Options

ApiAppOptions

Property Type Description
EnableSecurityHeaders bool Enable security headers middleware
ConfigureApi Action Configure API-specific options
ConfigureAfterRoutingCustomMiddleware Action Add custom middleware after routing
ConfigureBeforeEndpointsCustomMiddleware Action Add custom middleware before endpoints

ApiOptions

Property Type Default Description
AuthMode AuthenticationMode None Authentication mode (None/Authenticate/Authorize)

Middleware Pipeline

The ConfigureApiApp configures middleware in this order:

  1. Security Headers Middleware
  2. Swagger/OpenAPI
  3. Routing
  4. Custom Middleware (after routing hook)
  5. CORS
  6. Authentication & Authorization + RPT Middleware
  7. Custom Middleware (before endpoints hook)
  8. Endpoint Mapping (with Health Checks)

Common Patterns

Development vs Production

var options = builder.Services.AddApiServices(
    builder.Environment.IsDevelopment(),  // isDev flag
    builder.Configuration,
    opts => {
        // Development-specific config happens automatically
        // based on isDev flag
    });

Adding Custom Middleware

var options = builder.Services.AddApiServices(isDev, config, opts => {
    opts.ConfigureAfterRoutingCustomMiddleware = app => {
        app.UseMiddleware<RequestLoggingMiddleware>();
    };
    opts.ConfigureBeforeEndpointsCustomMiddleware = app => {
        app.UseMiddleware<TenantMiddleware>();
    };
});