![]() |
VOOZH | about |
dotnet add package FonsecaFramework.Asp --version 2026.6.18.1
NuGet\Install-Package FonsecaFramework.Asp -Version 2026.6.18.1
<PackageReference Include="FonsecaFramework.Asp" Version="2026.6.18.1" />
<PackageVersion Include="FonsecaFramework.Asp" Version="2026.6.18.1" />Directory.Packages.props
<PackageReference Include="FonsecaFramework.Asp" />Project file
paket add FonsecaFramework.Asp --version 2026.6.18.1
#r "nuget: FonsecaFramework.Asp, 2026.6.18.1"
#:package FonsecaFramework.Asp@2026.6.18.1
#addin nuget:?package=FonsecaFramework.Asp&version=2026.6.18.1Install as a Cake Addin
#tool nuget:?package=FonsecaFramework.Asp&version=2026.6.18.1Install as a Cake Tool
Base classes and extensions for ASP.NET Core web applications.
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.
dotnet add package FonsecaFramework.Asp
| 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 |
using FonsecaFramework.Asp;
var builder = WebApplication.CreateWindowsServiceBuilder(args);
builder.AddMvcServices()
.AddSwagger();
var app = builder.Build();
app.EnableSwagger()
.EnableMvc();
app.Run();
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>();
}
}
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}");
}
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));
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");
}
Copyright 2025 Steven Fonseca / VLR Creations
Licensed under the . You may use this library free of charge, provided you include the required attribution notices. See the file for full terms.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.6.18.1 | 0 | 6/18/2026 |
| 2026.6.13.1 | 86 | 6/13/2026 |
| 2026.6.4.2 | 97 | 6/4/2026 |
| 2026.6.4.1 | 108 | 6/4/2026 |
| 2026.6.3.3 | 100 | 6/4/2026 |
| 2026.6.3.2 | 101 | 6/4/2026 |
| 2026.6.3.1 | 96 | 6/3/2026 |
| 2026.5.21.1 | 103 | 5/22/2026 |
| 2026.5.20.1 | 111 | 5/20/2026 |
| 2026.5.12.1 | 109 | 5/13/2026 |
| 2026.5.11.1 | 110 | 5/11/2026 |
| 2026.5.7.2 | 114 | 5/7/2026 |
| 2026.5.7.1 | 101 | 5/7/2026 |
| 2026.5.6.1 | 100 | 5/6/2026 |
| 2026.5.5.1 | 101 | 5/5/2026 |
| 2026.5.2.1 | 100 | 5/2/2026 |
| 2026.4.30.1 | 110 | 4/30/2026 |
| 2026.4.29.1 | 127 | 4/29/2026 |
| 2026.4.27.1 | 109 | 4/28/2026 |
| 2026.4.22.1 | 103 | 4/22/2026 |