Table of Contents

Class TcgDexClient

Namespace
TcgDex
Assembly
TcgDex.CSharpSdk.dll

Entry point to the TCGdex API.

public sealed class TcgDexClient : ITcgDexClient, IDisposable

Inheritance

Implements

Inherited Members

Remarks

Resources are grouped the way the official SDKs group them, so client.Cards.GetAsync(id) here corresponds to tcgdex.card.get(id) there and the TCGdex documentation reads across without translation.

Constructors

TcgDexClient(HttpClient, TcgDexOptions?)

Creates a client over an existing System.Net.Http.HttpClient.

public TcgDexClient(HttpClient httpClient, TcgDexOptions? options = null)

Parameters

httpClient HttpClient

The client used for requests.

options TcgDexOptions?

Language and endpoint configuration. Defaults are used when omitted.

Remarks

Prefer AddTcgDex in applications that use dependency injection — it wires this up through IHttpClientFactory, which handles handler lifetime and connection reuse.

Exceptions

ArgumentNullException

httpClient is null.

ArgumentException

The options are not valid.

TcgDexClient(HttpClient, TcgDexOptions?, ILoggerFactory?)

Creates a client that logs through the supplied factory.

public TcgDexClient(HttpClient httpClient, TcgDexOptions? options, ILoggerFactory? loggerFactory)

Parameters

httpClient HttpClient

The client used for requests.

options TcgDexOptions?

Language and endpoint configuration.

loggerFactory ILoggerFactory?

Where SDK log messages are written.

Remarks

Registering through AddTcgDex supplies this automatically from the container, so this overload is for callers building the client by hand.

Exceptions

ArgumentNullException

httpClient is null.

ArgumentException

The options are not valid.

Properties

Cards

Card lookups.

public ICardResource Cards { get; }

Property Value

ICardResource

Catalog

The enumeration endpoints, for building filters and pickers.

public ICatalogResource Catalog { get; }

Property Value

ICatalogResource

Random

Random card, set and series.

public IRandomResource Random { get; }

Property Value

IRandomResource

Series

Series lookups.

public ISerieResource Series { get; }

Property Value

ISerieResource

Sets

Set lookups.

public ISetResource Sets { get; }

Property Value

ISetResource

Methods

Create(TcgDexOptions?, Action<TcgDexCacheOptions>?, ILoggerFactory?)

Creates a client with a correctly configured System.Net.Http.HttpClient, for applications without a dependency-injection container.

public static TcgDexClient Create(TcgDexOptions? options = null, Action<TcgDexCacheOptions>? configureCache = null, ILoggerFactory? loggerFactory = null)

Parameters

options TcgDexOptions?

Language and endpoint configuration.

configureCache Action<TcgDexCacheOptions>?

When supplied, enables response caching and applies this policy. Pass an empty delegate to enable it with defaults.

loggerFactory ILoggerFactory?

Optional destination for SDK log messages.

Returns

TcgDexClient

A client that owns and disposes its own System.Net.Http.HttpClient.

Examples

// Once, for the life of the application.
using TcgDexClient tcgdex = TcgDexClient.Create();

Card? card = await tcgdex.Cards.GetAsync("swsh3-136", cancellationToken);

Remarks

Create one and keep it. This exists so that callers outside a container do not have to know how to configure System.Net.Http.HttpClient correctly — but it cannot stop the one mistake that matters, which is creating a client per request.

The handler sets PooledConnectionLifetime, which a plain long-lived System.Net.Http.HttpClient does not: without it, connections are held indefinitely and never observe DNS changes. That is the failure a naive singleton runs into, and it is invisible until a host moves.

Exceptions

ArgumentException

The options are not valid.

Dispose()

Disposes the System.Net.Http.HttpClient this instance created.

public void Dispose()

Remarks

A client passed to the constructor belongs to the caller and is left untouched — disposing it here would break every other consumer sharing it, which is exactly the bug this ownership split prevents.