Corely.Billing 1.0.0

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

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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