bff-setup
Configure affolterNET.Web.Bff service registration and middleware pipeline. Use when setting up AddBffServices, ConfigureBffApp, or configuring the BFF middleware order.
When & Why to Use This Skill
This Claude skill streamlines the configuration of the affolterNET.Web.Bff service and middleware pipeline for .NET applications. It automates the setup of service registrations, security headers, and session management, ensuring a robust Backend-for-Frontend (BFF) architecture while maintaining optimal middleware execution order and security best practices.
Use Cases
- Initial setup of a Backend-for-Frontend (BFF) architecture in .NET projects to manage communication between frontend frameworks and backend APIs.
- Configuring comprehensive security middleware including CSRF (Antiforgery) protection, security headers, and HTTPS redirection with minimal manual coding.
- Implementing custom middleware hooks (e.g., for multi-tenancy or auditing) at specific points within the request-response pipeline.
- Managing environment-specific configurations for authentication modes and session management to ensure consistency across development and production environments.
| name | bff-setup |
|---|---|
| description | Configure affolterNET.Web.Bff service registration and middleware pipeline. Use when setting up AddBffServices, ConfigureBffApp, or configuring the BFF middleware order. |
BFF Setup
Configure the affolterNET.Web.Bff 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.AddBffServices(
builder.Environment.IsDevelopment(),
builder.Configuration,
opts => {
opts.EnableSecurityHeaders = true;
opts.ConfigureBff = bff => {
bff.AuthMode = AuthenticationMode.Authorize;
bff.EnableSessionManagement = true;
};
});
var app = builder.Build();
// Step 2: Configure middleware
app.ConfigureBffApp(options);
app.Run();
Configuration Options
BffAppOptions
| Property | Type | Description |
|---|---|---|
EnableSecurityHeaders |
bool | Enable security headers middleware |
ConfigureBff |
Action | Configure BFF-specific options |
ConfigureAfterRoutingCustomMiddleware |
Action | Add custom middleware after routing |
ConfigureBeforeEndpointsCustomMiddleware |
Action | Add custom middleware before endpoints |
BffOptions
| Property | Type | Default | Description |
|---|---|---|---|
AuthMode |
AuthenticationMode | None |
Authentication mode |
EnableSessionManagement |
bool | false |
Enable session management |
Middleware Pipeline
The ConfigureBffApp configures middleware in this order:
- Exception Handling
- Security Headers Middleware
- HTTPS Redirection
- Static Files
- Swagger/OpenAPI
- Routing
- Custom Middleware (after routing hook)
- CORS
- Antiforgery (CSRF protection)
- Authentication & Authorization
- Token Refresh Middleware
- RPT Middleware
- NoUnauthorizedRedirect Middleware (API routes)
- Antiforgery Token Middleware
- Custom Middleware (before endpoints hook)
- API 404 Handling
- Endpoint Mapping (Razor Pages, Controllers, YARP, Fallback)
Common Patterns
Development vs Production
var options = builder.Services.AddBffServices(
builder.Environment.IsDevelopment(), // isDev flag
builder.Configuration,
opts => {
// Development-specific config happens automatically
});
Adding Custom Middleware
var options = builder.Services.AddBffServices(isDev, config, opts => {
opts.ConfigureAfterRoutingCustomMiddleware = app => {
app.UseMiddleware<TenantMiddleware>();
};
opts.ConfigureBeforeEndpointsCustomMiddleware = app => {
app.UseMiddleware<AuditMiddleware>();
};
});
With Session Management
var options = builder.Services.AddBffServices(isDev, config, opts => {
opts.ConfigureBff = bff => {
bff.EnableSessionManagement = true;
};
});