Skip to content

feat: standalone TorBoxClient without DI + IDisposable#22

Merged
devRael1 merged 5 commits into
masterfrom
copilot/implement-plan-standalone-client
Apr 18, 2026
Merged

feat: standalone TorBoxClient without DI + IDisposable#22
devRael1 merged 5 commits into
masterfrom
copilot/implement-plan-standalone-client

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 18, 2026

Adds direct instantiation of TorBoxClient without requiring a DI container, while keeping the existing DI path fully functional.

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

// Full options
using TorBoxClient client = new(new TorBoxClientOptions { ApiKey = key, Timeout = TimeSpan.FromSeconds(60) });

// Builder
using TorBoxClient client = new(o => { o.ApiKey = key; o.Timeout = TimeSpan.FromSeconds(60); });

Core SDK

  • ITorBoxClient extends IDisposable
  • TorBoxClient: 3 public standalone constructors that create and own HttpClient instances; DI constructor marked [ActivatorUtilitiesConstructor]
  • Dispose() releases owned HttpClients in standalone mode, no-op in DI mode
  • AuthHandler: new AuthHandler(string apiKey) constructor for standalone; DI constructor must remain public (not internal) because the DI container only resolves public constructors, even on internal types
  • TorBoxClientOptions.MainApiVersionedUrl / RelayApiVersionedUrl: internalpublic (read-only computed)
  • RegisterCore simplified from explicit factory lambda to AddScoped<ITorBoxClient, TorBoxClient>()
  • ValidateBaseUrl enforces trailing / on base URLs for correct relative URI resolution

Tests

  • 10 unit tests: standalone constructors, argument validation, IDisposable contract (verifies ObjectDisposedException on disposed HttpClient, asserts actual HttpClient.Timeout via reflection)
  • 2 unit tests: AuthHandler(string) bearer injection
  • 2 integration tests: standalone client end-to-end (skip without TORBOX_API_KEY)

Samples & Docs

  • StandaloneSetupExample.cs demonstrating all 3 patterns; Program.cs menu updated (38 examples)
  • README, getting-started, configuration, architecture docs updated with standalone usage sections

CI/CD

  • Both workflows (ci.yml, integration-tests.yml) changed to manual-only (workflow_dispatch)
  • Removed pull_request_review trigger and the check-approval job (review approval gate) from both workflows

Verification

  • 490 unit tests, 111 schema tests, 45 integration tests — all pass
  • Build: 0 warnings across net6.0–net10.0
  • CodeQL: 0 alerts

Copilot AI and others added 3 commits April 18, 2026 11:58
…Handler string constructor

- ITorBoxClient extends IDisposable
- TorBoxClientOptions: MainApiVersionedUrl and RelayApiVersionedUrl are now public
- AuthHandler: add string apiKey constructor for standalone mode
- TorBoxClient: 3 public standalone constructors + DI constructor with [ActivatorUtilitiesConstructor]
- TorBoxClient: IDisposable implementation (disposes owned HttpClients in standalone mode)
- TorBoxServiceCollectionExtensions: simplified RegisterCore using AddScoped<ITorBoxClient, TorBoxClient>()

Agent-Logs-Url: https://github.com/devRael1/TorBoxSDK/sessions/872eff32-b524-402e-8001-6cb89ea05db2

Co-authored-by: devRael1 <91017912+devRael1@users.noreply.github.com>
- Unit tests: TorBoxClientTests.cs (10 tests) + AuthHandler string constructor tests (2 tests)
- Integration tests: StandaloneClientTests.cs (2 tests, skip without API key)
- Sample: StandaloneSetupExample.cs showing all 3 constructors
- Program.cs: updated menu (38 examples)
- README.md, docs/getting-started.md, docs/configuration.md, docs/architecture.md updated

Agent-Logs-Url: https://github.com/devRael1/TorBoxSDK/sessions/872eff32-b524-402e-8001-6cb89ea05db2

Co-authored-by: devRael1 <91017912+devRael1@users.noreply.github.com>
Rename _ownedMainClient → _ownedMainHttpClient, _ownedSearchClient → _ownedSearchHttpClient, _ownedRelayClient → _ownedRelayHttpClient to distinguish from API client properties.

Agent-Logs-Url: https://github.com/devRael1/TorBoxSDK/sessions/872eff32-b524-402e-8001-6cb89ea05db2

Co-authored-by: devRael1 <91017912+devRael1@users.noreply.github.com>
@devRael1 devRael1 marked this pull request as ready for review April 18, 2026 12:23
Copilot AI review requested due to automatic review settings April 18, 2026 12:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a standalone (non-DI) construction path for TorBoxClient while keeping the existing DI-based registration/usage intact, including explicit ownership/disposal of HttpClient instances in standalone mode.

Changes:

  • Introduces standalone TorBoxClient constructors (api key / options / configure delegate) and IDisposable behavior for owned HttpClients.
  • Updates DI registration to rely on [ActivatorUtilitiesConstructor] and simplifies ITorBoxClient registration.
  • Adds/updates unit + integration tests, examples, and docs to cover standalone usage.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/TorboxSDK.UnitTests/TorBoxClientTests.cs New unit tests for standalone constructors + dispose behavior.
tests/TorboxSDK.UnitTests/Http/AuthHandlerTests.cs Adds tests for AuthHandler(string apiKey) authorization header behavior.
tests/TorBoxSDK.IntegrationTests/Standalone/StandaloneClientTests.cs New live integration tests exercising standalone client end-to-end.
src/TorBoxSDK/TorBoxClientOptions.cs Makes versioned URL helpers public and documents computed behavior.
src/TorBoxSDK/TorBoxClient.cs Implements standalone constructors, owned HttpClient creation, and Dispose().
src/TorBoxSDK/ITorBoxClient.cs Extends ITorBoxClient to implement IDisposable.
src/TorBoxSDK/Http/Handlers/AuthHandler.cs Adds standalone ctor and DI ctor marked with [ActivatorUtilitiesConstructor].
src/TorBoxSDK/DependencyInjection/TorBoxServiceCollectionExtensions.cs Simplifies core registration to AddScoped<ITorBoxClient, TorBoxClient>().
src/TorBoxSDK.Examples/Program.cs Adds standalone setup example entry and renumbers menu options.
src/TorBoxSDK.Examples/GettingStarted/StandaloneSetupExample.cs New example demonstrating all standalone construction patterns + disposal.
docs/getting-started.md Documents standalone (no-DI) usage.
docs/configuration.md Updates options table + adds standalone configuration section.
docs/architecture.md Updates instantiation guidance to include standalone mode and disposal semantics.
README.md Adds standalone usage section with code snippets.

Comment thread tests/TorboxSDK.UnitTests/TorBoxClientTests.cs
Comment thread src/TorBoxSDK/TorBoxClient.cs
Comment thread src/TorBoxSDK/TorBoxClient.cs Outdated
Comment thread tests/TorboxSDK.UnitTests/TorBoxClientTests.cs
Comment thread tests/TorboxSDK.UnitTests/TorBoxClientTests.cs
@devRael1
Copy link
Copy Markdown
Owner

@copilot apply changes based on the comments in this thread

- Fix XML docs for TorBoxClient(string) — separate ArgumentNullException/ArgumentException
- ValidateBaseUrl now enforces trailing '/' for correct relative URI resolution
- Add [Collection("Integration")] to StandaloneClientTests for consistency
- Add XML remarks about TORBOX_API_KEY requirement to StandaloneClientTests
- Fix AAA convention in all TorBoxClientTests (proper Arrange/Act/Assert phases)
- Constructor_WithCustomTimeout now asserts actual HttpClient.Timeout via reflection
- Dispose_WhenStandalone now verifies ObjectDisposedException on disposed HttpClient

Agent-Logs-Url: https://github.com/devRael1/TorBoxSDK/sessions/fdfcedb2-eec4-4c4c-b7d5-db781219d4e3

Co-authored-by: devRael1 <91017912+devRael1@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 18, 2026

@copilot apply changes based on the comments in this thread

All 6 review comments addressed in commit f15af3a:

  1. XML docs for TorBoxClient(string apiKey) — now lists ArgumentNullException (null) and ArgumentException (empty) separately
  2. ValidateBaseUrl — now also rejects base URLs missing a trailing / to prevent incorrect relative URI resolution
  3. [Collection("Integration")] added to StandaloneClientTests + <remarks> about TORBOX_API_KEY
  4. AAA convention — all tests refactored with proper separate // Arrange, // Act, // Assert phases
  5. Constructor_WithCustomTimeout — now asserts HttpClient.Timeout via reflection instead of just checking sub-clients
  6. Dispose_WhenStandalone — renamed to Dispose_WhenStandalone_DisposesOwnedHttpClients, now verifies ObjectDisposedException on the disposed HttpClient

Copilot AI requested a review from devRael1 April 18, 2026 12:43
@devRael1
Copy link
Copy Markdown
Owner

@copilot modifie les workflows github afin d'executer les tests unitaires + intégrations uniquement manuellement. De plus, il ne faut pas lancer automatiquement ces workflows dès lors qu'une PR est approuvée (supprime le CI / Check All Reviews Approved)

- Remove `pull_request_review` trigger from both ci.yml and integration-tests.yml
- Remove `check-approval` job and all review-approval logic from both workflows
- Remove `pull-requests: read` permission (no longer needed)
- Both workflows now run only via manual dispatch

Agent-Logs-Url: https://github.com/devRael1/TorBoxSDK/sessions/c524e4af-a51a-4098-8ff4-ae57948ea792

Co-authored-by: devRael1 <91017912+devRael1@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 18, 2026

@copilot modifie les workflows github afin d'executer les tests unitaires + intégrations uniquement manuellement. De plus, il ne faut pas lancer automatiquement ces workflows dès lors qu'une PR est...

Done in d1aab4e. Both workflows (ci.yml and integration-tests.yml) now trigger only on workflow_dispatch (manual). Removed the pull_request_review trigger and the entire check-approval job (review approval logic) from both workflows.

Copilot AI requested a review from devRael1 April 18, 2026 13:41
@devRael1 devRael1 merged commit ddfad00 into master Apr 18, 2026
@devRael1 devRael1 deleted the copilot/implement-plan-standalone-client branch April 18, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants