Table of Contents

Dependency Injection

TorBoxSDK integrates with IServiceCollection through AddTorBox.

Registration model

AddTorBox(...) registers:

Sub-clients are internal implementation details and are not registered individually.

Correct consumption

services.AddTorBox(options =>
{
    options.ApiKey = Environment.GetEnvironmentVariable("TORBOX_API_KEY")
        ?? throw new InvalidOperationException("Missing TorBox API key.");
});

using ServiceProvider provider = services.BuildServiceProvider();
ITorBoxClient client = provider.GetRequiredService<ITorBoxClient>();

Standalone mode

For non-DI environments, instantiate TorBoxClient directly:

using TorBoxClient client = new("your-api-key");

Lifetime and disposal

  • In DI mode, the container controls HttpClient lifetime.
  • In standalone mode, dispose TorBoxClient with using.