Corely.Billing
2.1.0
dotnet add package Corely.Billing --version 2.1.0
NuGet\Install-Package Corely.Billing -Version 2.1.0
<PackageReference Include="Corely.Billing" Version="2.1.0" />
<PackageVersion Include="Corely.Billing" Version="2.1.0" />
<PackageReference Include="Corely.Billing" />
paket add Corely.Billing --version 2.1.0
#r "nuget: Corely.Billing, 2.1.0"
#:package Corely.Billing@2.1.0
#addin nuget:?package=Corely.Billing&version=2.1.0
#tool nuget:?package=Corely.Billing&version=2.1.0
Corely.Billing
Grants, consumption and quota for .NET applications. Records what an account was given, what it used, and whether any is left, kept reconciled across retries so a replayed unit of work is never charged twice.
Not only for metering: a subscription, prepaid credits, a trial, or seats use the same library with less of it. See Usage Shapes.
Try it running: three demo apps show the web components, a subscription, and Billing inside a Corely.IAM app. See Demos.
flowchart LR
options["<b>BillingOptions</b><br/>usage and hooks"] --> add["<b>AddBillingServices</b>"]
add --> grants["<b>IGrantService</b>"]
add --> quota["<b>IQuotaService</b>"]
add --> consumption["<b>IConsumptionService</b>"]
grants --> processors["<b>Processors</b><br/>internal"]
quota --> processors
consumption --> processors
processors --> db[("<b>Database</b><br/>Grants, ConsumptionEvents")]
cli["<b>corely-billing-db</b><br/>migration CLI"] --> db
classDef host fill:#dbeafe,stroke:#2563eb,color:#1e3a8a
classDef api fill:#dcfce7,stroke:#16a34a,color:#14532d
classDef internal fill:#fef3c7,stroke:#d97706,color:#78350f
classDef store fill:#f6f8fa,stroke:#8c959f,color:#24292f
class options,add host
class grants,quota,consumption api
class processors internal
class db,cli store
Highlights
- Grants: an account's allowance of a unit for an operation, valid for a window, limited or unlimited
- Reservations: quota is held before work starts and settled to what the work cost
- Grant-edge splitting: work larger than one grant's remainder draws from the next, soonest-expiring first
- Idempotent retries: a retried unit of work recognises its own earlier rows instead of charging twice
- Overdraft-once: work already paid for is always recorded, and the overrun stays visible
- Registered vocabulary: operations and units are host-defined tokens, validated on every write
- Host-owned authorization: decorate the public services; no identity library is referenced
- Two database providers: SQL Server and MySQL via EF Core
Quick Start
1. Create the database schema
The library never applies migrations at runtime. Create the schema with the migration tool, which ships both providers' migrations:
dotnet tool install --global Corely.Billing.DataAccessMigrations.Cli
corely-billing-db db create -p MsSql -c "Server=(localdb)\MSSQLLocalDB;Database=MyApp;Trusted_Connection=True;"
See the Migration CLI docs for deployment scripting, environment-variable configuration, and running against MySQL.
2. Register and use the services
var options = BillingOptions.Create(configuration, efConfigFactory)
.RegisterOperation("text_generation", "Text Generation")
.RegisterUnit("token", "token");
services.AddBillingServices(options);
using var scope = accessor.BeginScope(new OperationContext(correlationId, $"chat:{chatId}/turn:{turn}"));
await quotaService.ReserveAsync(new ReserveQuotaRequest(accountId, generation, token, maxTokens, "large-model"));
var reply = await GenerateAsync(prompt, maxTokens);
await quotaService.SettleAsync(new SettleQuotaRequest(accountId, generation, token, reply.TotalTokens));
Documentation
| Docs | Description |
|---|---|
| Corely.Billing | Core library: setup, services, reservations, architecture |
| Migration CLI | Database creation, migrations, and scripting |
| Corely.Billing.Web | Blazor components: grant list and editor, usage charts, usage events, CSV export |
| Corely.Billing.IAM | Corely.IAM permissions for grants, consumption and quota |
| Corely.Billing.Web.IAM | Each grant action in the web components gated by IAM's PermissionView |
| Demos | The three demo apps, what each shows, and how to run them |
Solution Structure
| Project | Purpose |
|---|---|
Corely.Billing |
Core library: grants, the consumption ledger, quota |
Corely.Billing.Web |
Blazor components and opt-in routed pages for grants and usage |
Corely.Billing.IAM |
Corely.IAM resource types and authorization decorators for the Billing services |
Corely.Billing.Web.IAM |
Corely.IAM.Web for the web components: the signed-in account and per-action gates |
Corely.Billing.ConsoleTest |
Zero-setup demo: grant, reserve, settle on SQLite |
Corely.Billing.Demos.Portal |
The web components against a seeded account, with simulated usage |
Corely.Billing.Demos.Subscription |
The smallest host: one unlimited grant per term gates a page |
Corely.Billing.Demos.WithIAM |
A metered host signed in through Corely.IAM, authorized by IAM permissions |
Corely.Billing.Demos.Bootstrap |
Bootstrap for the demos, served once |
Corely.Billing.UnitTests |
Unit tests on mock repositories |
Corely.Billing.IntegrationTests |
SQLite tests, plus an opt-in SQL Server and MySQL matrix |
Corely.Billing.Web.UnitTests |
bUnit tests for the web components |
Corely.Billing.IAM.UnitTests |
Unit tests for the IAM decorators and registration |
Corely.Billing.Web.IAM.UnitTests |
bUnit tests of the web components behind IAM's PermissionView |
Corely.Billing.Web.FunctionalTests |
In-process smoke tests for the demo hosts |
Corely.Billing.DataAccessMigrations.Cli |
Migration CLI that creates and migrates the billing schema (published as a .NET tool) |
Corely.Billing.DataAccessMigrations.MsSql / .MySql |
EF Core migrations per database provider, bundled into the CLI |
License
See LICENSE for details.
| 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
- Corely.Common (>= 2.0.3)
- Corely.DataAccess (>= 3.0.0)
- FluentValidation (>= 12.1.1)
- FluentValidation.DependencyInjectionExtensions (>= 12.1.1)
- Microsoft.EntityFrameworkCore (>= 10.0.11)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.11)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.11)
- Scrutor (>= 7.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Corely.Billing:
| Package | Downloads |
|---|---|
|
Corely.Billing.Web
Blazor components for Corely Billing: a grant list and editor, a usage chart, and a consumption table a host drops into its own pages |
|
|
Corely.Billing.IAM
Corely.IAM permissions for Corely.Billing: the grant, consumption and quota resource types and the decorators that check them |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.0 | 73 | 9/27/2026 |
| 2.0.0 | 73 | 9/26/2026 |
| 1.0.0 | 62 | 9/24/2026 |
| 1.0.0-preview.2 | 74 | 9/23/2026 |
| 1.0.0-preview.1 | 57 | 9/23/2026 |