Skip to content
bitzorcas
中EN

Reference

Web and API Infrastructure: Minimal API Generation and Middleware Topology

Explore the BitzOrcas.Modern Web API foundation. Learn [GenerateEndpoint] compile-time Minimal API bindings, ASP.NET Core middleware ordering, and RFC 9457 Problem Details.

Last updated

In modular monolith and microservice architectures, the role of the API Host is often misunderstood:

  • Teams pollute Controllers with domain business logic, turning controllers into unmaintainable bottlenecks;
  • Haphazard middleware ordering leads to tenant resolution running before authentication, causing critical access control vulnerabilities.

BitzOrcas.Modern enforces a strict architectural rule: The API Host is a Composition Root, not a business layer: All HTTP endpoints are bound at compile time via [GenerateEndpoint] into Native AOT-ready Minimal APIs, while use cases remain purely in Application vertical slices.

Middleware Topology and Request Pipeline

1. Inbound HTTP Request

2. Forwarded Headers + CORS + Security Headers

3. Authentication (JWT / API Key Verification)

4. Tenant Resolution (Resolves & Injects ICurrentTenant)

5. Rate Limiting + API Deprecation Guard

6. Minimal API Route Dispatch ([GenerateEndpoint])

7. Mediator Pipeline (10-Stage Pipeline Lifecycle)

8. Target Use Case Handler

9. Map Result to HTTP 200 or RFC 9457 Problem Details


Step 1: Declarative Minimal API Endpoints

Using [GenerateEndpoint], the Roslyn incremental generator emits high-performance static route mappings:

CreateNoteCommand.cs: Route Declaration
using BitzOrcas.Application.Abstractions.Authorization;
using BitzOrcas.Domain.Results;
using BitzOrcas.Endpoint.Attributes;
using Mediator;
namespace BitzOrcas.Sandbox.Application.Commands;
// Declarative endpoint: configures route, Swagger tags, and rate limit policies
[GenerateEndpoint(
HttpRoute.Post,
"/api/notes",
Tag = "Notes",
RateLimitPolicy = "userPolicy",
RequestTimeoutPolicy = "StandardCommand")]
public sealed record CreateNoteCommand(string Title)
: ICommand<Result<string>>, IAuthorizedRequest
{
// Authorization resource and action descriptor
public ResourceDescriptor Resource { get; } = new("sandbox", "note");
public AuthorizationAction Action { get; } = AuthorizationAction.Create;
}

Step 2: Standard RFC 9457 Problem Details Errors

When handlers return Result.Failure, the framework automatically serializes standard Problem Details:

HTTP 400 Validation Error Response
{
"type": "https://docs.bitzsoft.com/problems/validation",
"title": "Bad Request",
"status": 400,
"detail": "Customer name cannot exceed 100 characters.",
"instance": "/api/customers",
"errorCode": "Customer.NameTooLong",
"errorType": "Validation",
"traceId": "4bf92f3577b34da6a3ce929d0e0e4736"
}

Summary

BitzOrcas Web API infrastructure ensures maximum decoupling:

  • Compile-Time Static Dispatch: Sub-second container startups without runtime reflection;
  • Middleware Ordering Contract: Enforces strict security pipeline guarantees;
  • RFC Industry Standards: Consistent Problem Details streamline frontend error integration.

100%

Scroll or use controls to zoom · drag when enlarged · double-click for 100% / 200%