feat: standalone TorBoxClient without DI + IDisposable#22
Conversation
…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>
There was a problem hiding this comment.
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
TorBoxClientconstructors (api key / options / configure delegate) andIDisposablebehavior for ownedHttpClients. - Updates DI registration to rely on
[ActivatorUtilitiesConstructor]and simplifiesITorBoxClientregistration. - 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. |
|
@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>
All 6 review comments addressed in commit
|
|
@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>
Done in |
Adds direct instantiation of
TorBoxClientwithout requiring a DI container, while keeping the existing DI path fully functional.Core SDK
ITorBoxClientextendsIDisposableTorBoxClient: 3 public standalone constructors that create and ownHttpClientinstances; DI constructor marked[ActivatorUtilitiesConstructor]Dispose()releases ownedHttpClients in standalone mode, no-op in DI modeAuthHandler: newAuthHandler(string apiKey)constructor for standalone; DI constructor must remainpublic(notinternal) because the DI container only resolves public constructors, even on internal typesTorBoxClientOptions.MainApiVersionedUrl/RelayApiVersionedUrl:internal→public(read-only computed)RegisterCoresimplified from explicit factory lambda toAddScoped<ITorBoxClient, TorBoxClient>()ValidateBaseUrlenforces trailing/on base URLs for correct relative URI resolutionTests
IDisposablecontract (verifiesObjectDisposedExceptionon disposedHttpClient, asserts actualHttpClient.Timeoutvia reflection)AuthHandler(string)bearer injectionTORBOX_API_KEY)Samples & Docs
StandaloneSetupExample.csdemonstrating all 3 patterns;Program.csmenu updated (38 examples)CI/CD
ci.yml,integration-tests.yml) changed to manual-only (workflow_dispatch)pull_request_reviewtrigger and thecheck-approvaljob (review approval gate) from both workflowsVerification