Muonroi.Quota.Abstractions 1.0.0-alpha.16

This is a prerelease version of Muonroi.Quota.Abstractions.
dotnet add package Muonroi.Quota.Abstractions --version 1.0.0-alpha.16
                    
NuGet\Install-Package Muonroi.Quota.Abstractions -Version 1.0.0-alpha.16
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Muonroi.Quota.Abstractions" Version="1.0.0-alpha.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muonroi.Quota.Abstractions" Version="1.0.0-alpha.16" />
                    
Directory.Packages.props
<PackageReference Include="Muonroi.Quota.Abstractions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Muonroi.Quota.Abstractions --version 1.0.0-alpha.16
                    
#r "nuget: Muonroi.Quota.Abstractions, 1.0.0-alpha.16"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Muonroi.Quota.Abstractions@1.0.0-alpha.16
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Muonroi.Quota.Abstractions&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.Quota.Abstractions&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Tool

Muonroi.Quota.Abstractions

Quota tracking contracts and in-memory implementations for Muonroi multi-tenant applications.

NuGet License: Apache 2.0

This package defines the core quota management contracts (ITenantQuotaTracker, ITenantQuotaStore) and ships ready-to-use in-memory implementations for development and testing. It also provides TenantQuota limit models, tier-based presets (Free → Enterprise), and the QuotaType enum that enumerates every tracked resource dimension. Higher-tier packages (e.g. Muonroi.Tenancy.SiteProfile.Web) consume these contracts to enforce per-tenant limits at the middleware or behavior layer.

Installation

dotnet add package Muonroi.Quota.Abstractions --prerelease

Quick Start

Register the in-memory quota store and tracker, then inject ITenantQuotaTracker wherever enforcement is needed:

// Program.cs
builder.Services.AddTenantQuotaManagement();   // registers InMemoryTenantQuotaStore (singleton)
                                                // and InMemoryTenantQuotaTracker (scoped)

// Apply a tier preset for a known tenant
var store = app.Services.GetRequiredService<ITenantQuotaStore>();
await store.SaveQuotaAsync("tenant-123", TenantQuotaPresets.Starter);

// In a request handler or background service
public class RuleExecutionService(ITenantQuotaTracker quota)
{
    public async Task RunAsync(string tenantId, CancellationToken ct)
    {
        bool allowed = await quota.CheckQuotaAsync(
            tenantId, QuotaType.RuleExecutionsPerDay, amount: 1, ct);

        if (!allowed)
            throw new QuotaExceededException($"Tenant {tenantId} has exceeded daily rule executions.");

        // ... execute rule ...
        await quota.IncrementUsageAsync(tenantId, QuotaType.RuleExecutionsPerDay, amount: 1, ct);
    }
}

Features

  • ITenantQuotaTracker — check quota availability and record usage in two separate steps, keeping enforcement logic decoupled from storage.
  • ITenantQuotaStore — read/write TenantQuota limits and QuotaUsage snapshots; reset daily counters.
  • InMemoryTenantQuotaTracker / InMemoryTenantQuotaStore — thread-safe volatile implementations; suitable for development, testing, and single-node deployments.
  • TenantQuotaPresets — static factory properties (Free, Starter, Professional, Enterprise) with calibrated defaults for every quota dimension including MaxPdfRendersPerDay.
  • QuotaType enum — 14 resource dimensions: RuleExecutionsPerDay, ConcurrentExecutions, ApiRequestsPerMinute, RuleEvaluationsPerSecond, WorkflowExecutionsPerHour, StorageUsageMB, TotalRules, TotalDecisionTables, TotalWorkflows, TotalConnectors, ConnectorExecutionsPerDay, MessagesPerDay, MessagesPerMinute, PdfRendersPerDay.
  • QuotaExceededException — domain exception (HTTP 429) thrown when a limit is breached; extends MException with code QUOTA_EXCEEDED.
  • TenantTier enum — Free, Starter, Professional, Enterprise.
  • AddTenantQuotaManagement() extension — single-call DI registration using TryAdd* (safe to call multiple times).

Configuration

// Minimal registration — in-memory defaults
services.AddTenantQuotaManagement();

// Override the store with a persistent implementation (e.g. Redis, SQL)
// by registering before calling AddTenantQuotaManagement, or replacing afterwards:
services.AddSingleton<ITenantQuotaStore, MyRedisQuotaStore>();
services.AddTenantQuotaManagement();   // TryAddSingleton is a no-op when already registered

Quota limits are stored as a TenantQuota object per tenant. Seed limits at startup using ITenantQuotaStore.SaveQuotaAsync or use a preset:

Preset MaxRuleExecutionsPerDay MaxPdfRendersPerDay Notes
Free 1 000 50 Default when no quota is found
Starter 10 000 500
Professional 100 000 5 000
Enterprise int.MaxValue int.MaxValue Unlimited

API Reference

Type Purpose
ITenantQuotaTracker Check and increment per-tenant usage; reset daily counters
ITenantQuotaStore Persist TenantQuota limits and read QuotaUsage snapshots
InMemoryTenantQuotaTracker Scoped in-memory tracker; delegates storage to ITenantQuotaStore
InMemoryTenantQuotaStore Singleton volatile store backed by a ConcurrentDictionary
TenantQuota Limit model — one property per QuotaType dimension
TenantQuotaPresets Static tier presets (Free, Starter, Professional, Enterprise)
QuotaType Enum of 14 trackable resource dimensions
TenantTier Enum of 4 subscription tiers
QuotaUsage Snapshot of CurrentUsage and Limits dictionaries keyed by QuotaType
QuotaExceededException HTTP-429 domain exception (code QUOTA_EXCEEDED)
TenantQuotaServiceCollectionExtensions AddTenantQuotaManagement() DI helper

Samples

No dedicated sample exists for this package. The integration-test suite at samples/TestProject.Service.IntegrationTests/SiteQuotaEnforcementTests.cs demonstrates implementing a custom ITenantQuotaTracker and exercising per-tenant quota enforcement.

Compatibility

  • Target framework: net8.0
  • License: Apache-2.0 (OSS)

License

Licensed under the Apache License 2.0.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Muonroi.Quota.Abstractions:

Package Downloads
Muonroi.RuleEngine.Abstractions

Rule Engine Abstractions for Muonroi.BuildingBlock

Muonroi.Tenancy.Abstractions

Multi-tenancy contracts: ITenantContext, ITenantIdResolver, and shared tenant models for Muonroi applications.

Muonroi.Tenancy.Core

Shared-database multi-tenancy core: EF Core global filters, tenant context propagation, and quota tracking.

Muonroi.Tenancy.SiteProfile.Web

ASP.NET Core middleware and SignalR hot-reload for Muonroi.Tenancy.SiteProfile.

Muonroi.Billing.Abstractions

Product-agnostic billing seam contracts for Muonroi multi-tenant applications. Contains IBillingProvider, IUsageAggregator, BillableEvent, UsageLineItem, PricingPlan and a record-only default provider. No payment-SDK dependency; the payment-processor adapter is a deferred, separate implementation behind this seam.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha.16 279 6/22/2026
1.0.0-alpha.15 303 5/31/2026
1.0.0-alpha.14 279 5/15/2026
1.0.0-alpha.13 232 5/2/2026
1.0.0-alpha.12 115 4/2/2026
1.0.0-alpha.11 166 4/2/2026
1.0.0-alpha.9 123 3/30/2026
1.0.0-alpha.8 349 3/28/2026
1.0.0-alpha.7 78 3/27/2026
1.0.0-alpha.5 78 3/27/2026
1.0.0-alpha.4 75 3/27/2026
1.0.0-alpha.3 75 3/27/2026
1.0.0-alpha.2 64 3/26/2026