Repository navigation
Getting Started
dotnet add package EmmaSharperEmma issues a public key and a private key per account, plus an account id. All three come from the Emma UI under account settings. The library sends the keys as HTTP Basic auth; you never construct the header yourself.
using EmmaSharper;
builder.Services.AddEmmaApiProviders(options =>
{
options.AccountId = "your account id";
options.PublicKey = "your public key";
options.SecretKey = "your secret key";
// options.BaseUrl defaults to https://api.e2ma.net
// options.Timeout defaults to 30 seconds
});Or bind from configuration — this reads the Emma section:
builder.Services.AddEmmaApiProviders(builder.Configuration);{
"Emma": {
"AccountId": "your account id",
"PublicKey": "your public key",
"SecretKey": "your secret key"
}
}To bind the configuration root instead of a section — keys at the top level of
appsettings.json— passsectionName: null.
Keep the secret key out of source control — user secrets in development, and your platform's secret store in production.
Inject whichever provider you need:
public sealed class MemberReport(IEmmaMemberProvider members)
{
public async Task<int> CountActiveAsync(CancellationToken ct)
=> await members.GetMemberCount(status: MemberStatusShort.Active, cancellationToken: ct);
}Most parameters are optional, so name the ones you pass — including cancellationToken, since it
is the trailing parameter on every method.
AddEmmaApiProviders validates on first resolve rather than failing on the first HTTP call:
-
PublicKeyandSecretKeymust be present -
BaseUrlmust be an absolute URI
A missing key throws OptionsValidationException at startup, not a confusing 401 an hour later.
One pooled HttpClient via IHttpClientFactory, shared across every provider and every account
scope. Providers are transient and stateless; the client and its handler are managed by the
factory, so there is no socket exhaustion and no stale DNS.
- Addressing more than one account → Enterprise and Multiple Accounts
- Fetching more than 500 records → Paging
- Before you run anything at volume → Rate Limiting and Resilience
Using it
Reference
Links