Corely.Billing
1.0.0
dotnet add package Corely.Billing --version 1.0.0
NuGet\Install-Package Corely.Billing -Version 1.0.0
<PackageReference Include="Corely.Billing" Version="1.0.0" />
<PackageVersion Include="Corely.Billing" Version="1.0.0" />
<PackageReference Include="Corely.Billing" />
paket add Corely.Billing --version 1.0.0
#r "nuget: Corely.Billing, 1.0.0"
#:package Corely.Billing@1.0.0
#addin nuget:?package=Corely.Billing&version=1.0.0
#tool nuget:?package=Corely.Billing&version=1.0.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.
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("document_extraction", "Document Extraction")
.RegisterUnit("page", "page");
services.AddBillingServices(options);
using var scope = accessor.BeginScope(new OperationContext(correlationId, $"job:{jobId}/step:extract"));
await quotaService.ReserveAsync(new ReserveQuotaRequest(accountId, extraction, page, 1, "mistral"));
var pages = await ExtractAsync(document);
await quotaService.SettleAsync(new SettleQuotaRequest(accountId, extraction, page, pages));
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 chart, usage events |
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.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.Assets |
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.Web.FunctionalTests |
In-process smoke tests for the demo hosts |
Corely.Billing.DataAccessMigrations.Cli |
Migration CLI — 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 (1)
Showing the top 1 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 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 0 | 9/24/2026 |
| 1.0.0-preview.2 | 0 | 9/23/2026 |
| 1.0.0-preview.1 | 0 | 9/23/2026 |