About this project
Soenneker.Copper.OpenApiClientUtil is a .NET library that hands out a lazily created, reusable Kiota-generated client for the Copper API, built on top of a configured Copper HTTP provider.
What it does
- Exposes an `ICopperOpenApiClientUtil` abstraction whose `Get` method initializes the client once for the utility's lifetime; concurrent callers share that initialization and receive the same client instance.
- Sits above a Copper HTTP package that sends the headers Copper requires: `X-PW-AccessToken`, `X-PW-Application` and `X-PW-UserEmail`.
- Configuration is read from a `Copper` section (for example `ApiKey` and `Email` for the token owner), and the underlying package also supports `Copper:ClientBaseUrl`, `Copper:Application`, `Copper:AuthHeaderName` and `Copper:AuthHeaderValueTemplate`.
Installation and registration
Install via `dotnet add package Soenneker.Copper.OpenApiClientUtil`. Two DI registrars are provided: `AddCopperOpenApiClientUtilAsSingleton()` for a single shared client, and `AddCopperOpenApiClientUtilAsScoped()` when each application scope should cache its own generated client while still sharing the singleton HTTP provider.
Typical usage
A consumer class injects `ICopperOpenApiClientUtil`, awaits `clientUtil.Get(cancellationToken)` and then calls generated endpoint methods such as `client.Account.GetAsync(...)`.
Documented caveats
- Configuration is captured when the underlying HTTP client is first created, so credentials or base URL changes require recreating the service lifetime.
- Disposing a scoped utility releases its generated-client reference without removing the shared `HttpClient`; the HTTP provider disposes that client when the application container shuts down.
- Some generated endpoints return JSON as `string?` because the source Postman collection lacks a strong response schema.
- The API key, token-owner email and Copper authentication headers should be redacted from logs and traces.
Scope
The repository is a thin client wrapper, not a full CRM application: it provides client creation and lifetime management, while API coverage and response shapes are defined by the generated Copper client.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.