FonsecaFramework.Asp
2026.5.12.1
dotnet add package FonsecaFramework.Asp --version 2026.5.12.1
NuGet\Install-Package FonsecaFramework.Asp -Version 2026.5.12.1
<PackageReference Include="FonsecaFramework.Asp" Version="2026.5.12.1" />
<PackageVersion Include="FonsecaFramework.Asp" Version="2026.5.12.1" />
<PackageReference Include="FonsecaFramework.Asp" />
paket add FonsecaFramework.Asp --version 2026.5.12.1
#r "nuget: FonsecaFramework.Asp, 2026.5.12.1"
#:package FonsecaFramework.Asp@2026.5.12.1
#addin nuget:?package=FonsecaFramework.Asp&version=2026.5.12.1
#tool nuget:?package=FonsecaFramework.Asp&version=2026.5.12.1
FonsecaFramework.Asp
Base classes and extensions for ASP.NET Core web applications.
Overview
FonsecaFramework.Asp is a .NET 10 library that provides a fluent builder API for configuring ASP.NET Core applications. It includes helpers for MVC, Razor Pages, Swagger, OAuth2 JWT authentication with token refresh, Windows Service hosting, timed background services with business-hour awareness, a base API controller, and an AI-powered dynamic rate limiter that uses ML.NET to adapt limits based on real-time traffic telemetry.
Installation
dotnet add package FonsecaFramework.Asp
Features
| Area | Key Classes / Methods |
|---|---|
| App Builder | WebApplication.CreateWindowsServiceBuilder(), .AddMvcServices(), .AddRazorServices(), .AddSwagger() |
| App Middleware | .EnableSwagger(), .EnableMvc(), .EnableRazor() |
| OAuth2 / JWT | OAuth.AddOAuth2Server(), OAuth.EnableOAuth2Server() — JWT authentication with /login and /refresh_token endpoints |
| User Service | IUserService — implement to provide custom user authentication |
| Base Controller | BaseApiController — pre-configured [ApiController] with [Route("[controller]")] |
| Background Tasks | TimedHostedService — recurring background work with optional business-hour constraints |
| Dynamic Rate Limiting | AddDynamicRateLimiter() — sliding-window rate limiter with runtime-configurable parameters |
| AI Rate Limiting | AiDynamicRateLimiterController, AiRateLimitingMiddleware — ML-driven rate limiting that learns from live traffic patterns |
| Settings | DynamicRateLimiterSettings — configuration object for rate-limiter policies |
Examples
Quick API Setup with Swagger and MVC
using FonsecaFramework.Asp;
var builder = WebApplication.CreateWindowsServiceBuilder(args);
builder.AddMvcServices()
.AddSwagger();
var app = builder.Build();
app.EnableSwagger()
.EnableMvc();
app.Run();
Add OAuth2 JWT Authentication
using FonsecaFramework.Asp;
var builder = Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(args);
// Register your IUserService implementation
builder.Services.AddSingleton<IUserService, MyUserService>();
// Configure JWT authentication
builder.AddOAuth2Server(
ValidIssuer: "https://myapp.com",
ValidAudience: "https://myapp.com",
Key: "YourSuperSecretKeyAtLeast32Characters!");
builder.AddMvcServices()
.AddSwagger();
var app = builder.Build();
// This adds /login and /refresh_token endpoints automatically
app.EnableOAuth2Server(
TokenIssuer: "https://myapp.com",
TokenAudience: "https://myapp.com",
TokenKey: "YourSuperSecretKeyAtLeast32Characters!");
app.EnableSwagger()
.EnableMvc();
app.Run();
Implement the IUserService interface to provide your own user authentication:
using FonsecaFramework.Asp;
public class MyUserService : IUserService
{
public async Task<IEnumerable<Claim>> GetUserClaimsWithUserAndPassword(
string username, string password)
{
// Validate credentials and return claims
if (username == "admin" && password == "secret")
{
return new[]
{
new Claim(ClaimTypes.Name, username),
new Claim(ClaimTypes.Role, "Admin")
};
}
return Enumerable.Empty<Claim>();
}
}
Base API Controller
Inherit from BaseApiController to get [ApiController] and [Route("[controller]")] applied automatically:
using FonsecaFramework.Asp;
using Microsoft.AspNetCore.Mvc;
public class ProductsController : BaseApiController
{
[HttpGet]
public IActionResult GetAll() => Ok(new[] { "Widget", "Gadget" });
[HttpGet("{id}")]
public IActionResult GetById(int id) => Ok($"Product {id}");
}
Timed Background Service
Run a recurring task with optional business-hour restrictions:
using FonsecaFramework.Asp;
var builder = Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(args);
// Run every 5 minutes, only between 8 AM and 6 PM
builder.Services.AddTimedHostedService(
doWork: (serviceProvider) =>
{
Console.WriteLine($"Background work at {DateTime.Now}");
},
startBusinessHour: DateTime.Today.AddHours(8),
endBusinessHour: DateTime.Today.AddHours(18),
frequency: TimeSpan.FromMinutes(5));
// Or run 24/7 with no business-hour restriction
builder.Services.AddTimedHostedService(
doWork: (sp) => Console.WriteLine("Always running"),
frequency: TimeSpan.FromMinutes(1));
AI-Powered Dynamic Rate Limiting
Rate limits that automatically adapt based on live traffic patterns using ML.NET:
using FonsecaFramework.Asp;
using FonsecaFramework.Asp.RateLimiting;
var builder = Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(args);
builder.Services.AddAiDynamicRateLimiter("ai-policy");
builder.AddMvcServices();
var app = builder.Build();
// Collect request telemetry (add early in pipeline)
app.UseAiRateLimitingTelemetry();
app.UseRateLimiter();
app.EnableMvc();
app.Run();
Apply the policy to controllers:
using Microsoft.AspNetCore.RateLimiting;
[EnableRateLimiting("ai-policy")]
public class WeatherController : BaseApiController
{
[HttpGet]
public IActionResult Get() => Ok("Hello");
}
Requirements
- .NET 10.0
License
Copyright 2025 Steven Fonseca / VLR Creations
Licensed under the Apache License, Version 2.0. You may use this library free of charge, provided you include the required attribution notices. See the LICENSE file for full terms.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- FonsecaFramework.Ai (>= 2026.5.12.1)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.8)
- Microsoft.Bcl.Memory (>= 10.0.8)
- Microsoft.Extensions.Hosting.WindowsServices (>= 10.0.8)
- Newtonsoft.Json (>= 13.0.4)
- Swashbuckle.AspNetCore (>= 10.1.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.5.12.1 | 74 | 5/13/2026 |
| 2026.5.11.1 | 90 | 5/11/2026 |
| 2026.5.7.2 | 97 | 5/7/2026 |
| 2026.5.7.1 | 87 | 5/7/2026 |
| 2026.5.6.1 | 87 | 5/6/2026 |
| 2026.5.5.1 | 89 | 5/5/2026 |
| 2026.5.2.1 | 88 | 5/2/2026 |
| 2026.4.30.1 | 99 | 4/30/2026 |
| 2026.4.29.1 | 115 | 4/29/2026 |
| 2026.4.27.1 | 97 | 4/28/2026 |
| 2026.4.22.1 | 91 | 4/22/2026 |
| 2026.4.21.1 | 94 | 4/21/2026 |
| 2026.4.20.1 | 93 | 4/20/2026 |
| 2026.4.15.1 | 101 | 4/15/2026 |
| 2026.4.13.1 | 101 | 4/13/2026 |
| 2026.4.10.1 | 102 | 4/10/2026 |
| 2026.4.8.1 | 103 | 4/8/2026 |
| 2026.4.7.1 | 104 | 4/7/2026 |
| 2026.4.3.1 | 99 | 4/3/2026 |
| 2026.4.1.1 | 105 | 4/1/2026 |