Muonroi.Quota.Abstractions 2.0.2

dotnet add package Muonroi.Quota.Abstractions --version 2.0.2
                    
NuGet\Install-Package Muonroi.Quota.Abstractions -Version 2.0.2
                    
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="2.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muonroi.Quota.Abstractions" Version="2.0.2" />
                    
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 2.0.2
                    
#r "nuget: Muonroi.Quota.Abstractions, 2.0.2"
                    
#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@2.0.2
                    
#: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=2.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.Quota.Abstractions&version=2.0.2
                    
Install as a Cake Tool

Muonroi.Quota.Abstractions

Contracts and base implementations for multi-tenant quota and rate limit tracking.

NuGet License

Overview

The Muonroi.Quota.Abstractions package provides the foundational contracts for enforcing usage limits (quotas) in a multi-tenant application. In SaaS environments, it's critical to control the resources consumed by individual tenants—whether that's the number of active users, storage size, or the rate of API calls/messages processed.

This package defines the interfaces required to read tenant limits (ITenantQuotaStore) and record/check usage (ITenantQuotaTracker). It also provides lightweight in-memory implementations suitable for development, testing, or single-node deployments. For distributed production environments, these contracts are typically implemented using distributed caches (like Redis) by higher-level packages.

Features

  • Standardized Quota Contracts: ITenantQuotaTracker and ITenantQuotaStore define a clear boundary for quota management, allowing the underlying storage mechanism to be swapped without affecting business logic.
  • Quota Types: The QuotaType categorization limits (e.g., API calls, Storage, Entities created), providing a unified vocabulary across the system.
  • Exception Models: Provides the standard QuotaExceededException, which can be caught by centralized exception handlers to return appropriate HTTP status codes (e.g., 429 Too Many Requests or 402 Payment Required).
  • In-Memory Fallbacks: Includes thread-safe, ConcurrentDictionary-backed implementations (InMemoryTenantQuotaStore, InMemoryTenantQuotaTracker) for rapid local development.
  • DI Registration: Easy wiring into the dependency injection container via TenantQuotaServiceCollectionExtensions.

Installation

dotnet add package Muonroi.Quota.Abstractions

Quick Start

Basic Configuration

Register the in-memory implementations for local development or testing.

using Microsoft.Extensions.DependencyInjection;
using Muonroi.Quota.Abstractions;

var builder = WebApplication.CreateBuilder(args);

// Registers InMemoryTenantQuotaStore and InMemoryTenantQuotaTracker
builder.Services.AddInMemoryTenantQuotas();

Checking Quotas in Business Logic

Inject the ITenantQuotaTracker into your services to enforce limits before performing actions.

using Muonroi.Quota.Abstractions;

public class DocumentService
{
    private readonly ITenantQuotaTracker _quotaTracker;

    public DocumentService(ITenantQuotaTracker quotaTracker)
    {
        _quotaTracker = quotaTracker;
    }

    public async Task CreateDocumentAsync(string tenantId)
    {
        // Attempt to consume the quota. This will throw a QuotaExceededException 
        // if the tenant lacks sufficient allowance.
        await _quotaTracker.ConsumeAsync(tenantId, QuotaType.DocumentsCreated, 1);
        
        // ... proceed
    }
}

API Reference

Core Contracts

  • ITenantQuotaStore: Persists and retrieves the maximum allowable limits configured for a given tenant.
  • ITenantQuotaTracker: Tracks current usage and increments counts. Defines ConsumeAsync and GetUsageAsync.

Models & Exceptions

  • TenantQuota: A configuration model representing a limit.
  • QuotaUsage: A state model representing current consumption against the limit.
  • QuotaType: Identifiers for the resource being consumed.
  • QuotaExceededException: Thrown by ITenantQuotaTracker.ConsumeAsync when a tenant attempts to exceed their limit.

Ecosystem Combinations

+ Muonroi.Tenancy.Core → Automated Tenant Throttling

By integrating ITenantQuotaTracker with ISystemExecutionContextAccessor, middleware can automatically intercept incoming HTTP requests, extracting the TenantId and aggressively returning 429 Too Many Requests if the tenant's daily quota limit is reached.

+ Muonroi.Governance.Enterprise → Tier-Based Allowances

Enterprise licenses integrate directly with ITenantQuotaStore to sync SaaS plans (e.g., Free vs Premium tiers). As a tenant's license upgrades, the store automatically raises the upper bounds on QuotaType.DocumentsCreated.

Full Quota Stack

builder.Services
    .AddInMemoryTenantQuotas();

Samples

License

Apache 2.0 — see LICENSE-APACHE.

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
2.0.2 971 8/26/2026
2.0.1 827 8/26/2026
2.0.0 848 8/14/2026