一键导入
planforge-new-middleware
Scaffold ASP.NET Core middleware with request/response pipeline, DI support, structured logging, and proper ordering.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Scaffold ASP.NET Core middleware with request/response pipeline, DI support, structured logging, and proper ordering.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Run a comprehensive code review across architecture, security, testing, naming, and patterns. Invokes relevant reviewer agents in sequence. Use before merging features or at the end of a phase. With --quorum, dispatches multi-model analysis for higher confidence.
Audit UI components for WCAG 2.2 compliance, semantic HTML, ARIA labels, keyboard navigation, color contrast, and responsive design.
Audit API endpoints for backward compatibility, versioning, OpenAPI compliance, pagination, rate limiting, and RFC 9457 error responses.
Review code for architecture violations: layer separation, sync-over-async, missing CancellationToken, improper DI. Use for PR reviews or code audits.
Fix a bug using TDD: reproduce with a failing test first, then implement the fix, then verify. Prevents regressions.
Review CI/CD pipelines for best practices: environment promotion, secrets management, rollback strategies, build caching, and deployment safety.
| name | planforge-new-middleware |
| description | Scaffold ASP.NET Core middleware with request/response pipeline, DI support, structured logging, and proper ordering. |
| metadata | {"author":"plan-forge","source":".github/prompts/new-middleware.prompt.md"} |
Scaffold an ASP.NET Core middleware component for the HTTP request pipeline.
public class {Name}Middleware(
RequestDelegate next,
ILogger<{Name}Middleware> logger)
{
public async Task InvokeAsync(HttpContext context)
{
// Pre-processing (before the next middleware)
logger.LogDebug("{Name}Middleware executing for {Path}", context.Request.Path);
try
{
await next(context);
}
finally
{
// Post-processing (after the response)
}
}
}
// Extension method for clean registration
public static class {Name}MiddlewareExtensions
{
public static IApplicationBuilder Use{Name}(this IApplicationBuilder builder)
=> builder.UseMiddleware<{Name}Middleware>();
}
// Use when the middleware needs scoped services
public class {Name}Middleware(ILogger<{Name}Middleware> logger) : IMiddleware
{
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
// Access scoped services directly via constructor injection
await next(context);
}
}
// Must register in DI
builder.Services.AddScoped<{Name}Middleware>();
// Order matters! Follow this sequence:
app.UseExceptionHandler(); // 1. Error handling (outermost)
app.UseCorrelationId(); // 2. Correlation ID
app.UseRequestLogging(); // 3. Request logging
app.UseAuthentication(); // 4. Authentication
app.UseAuthorization(); // 5. Authorization
app.UseRateLimiting(); // 6. Rate limiting
app.Use{Name}(); // 7. Your custom middleware
| Type | Purpose | Example |
|---|---|---|
| Correlation ID | Attach trace ID to every request | Read/generate X-Correlation-Id header |
| Tenant Resolution | Extract tenant from token/header | Set ITenantContext.TenantId |
| Request Logging | Log method, path, status, duration | Structured log with Serilog |
| Exception Handling | Map exceptions to ProblemDetails | Global try/catch with RFC 9457 |
await next(context) unless short-circuiting intentionallyfinally blocks for post-processing (guarantees execution on errors)Use{Name}() for clean Program.cs registrationIMiddleware interface when scoped DI services are needed