You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix hybrid configuration for basic authentication credentials
Fixes#67
## Problem
When using hybrid configuration (binding from appsettings.json combined with
programmatic overrides), basic authentication credentials set programmatically
were not being applied to requests. Users expected to be able to override
appsettings.json values with programmatic configuration, particularly for
sensitive credentials like BasicAuthUsername and BasicAuthPassword.
## Root Cause
The service registration API didn't properly support the .NET options pattern
for applying configuration overrides. Options need to be configured using
PostConfigure to ensure overrides run after all other configuration sources.
## Solution
Simplified the API to use standard .NET options configuration patterns:
1. **Removed custom options helper** - Users now use standard `AddOptions<T>()`
2. **Added non-generic overloads** - `AddGotenbergSharpClient()` defaults to `GotenbergSharpClientOptions` for simpler API
3. **Use `GetRequiredService`** - Changed from nullable `GetService` to fail fast if options aren't registered
4. **Updated documentation** - All examples now show proper use of `PostConfigure` for overrides
## Changes
- **TypedClientServiceCollectionExtensions.cs**: Simplified API, added non-generic overloads, updated XML docs
- **BasicAuthTests.cs**: Updated tests to use standard options patterns, added hybrid config tests
- **README.md**: Fixed all configuration examples to show correct patterns
- **DIExample/Program.cs**: Updated to use simplified non-generic API
## Usage
```csharp
// Hybrid configuration (appsettings + programmatic overrides)
services.AddOptions<GotenbergSharpClientOptions>()
.Bind(Configuration.GetSection("GotenbergSharpClient"))
.PostConfigure(options =>
{
// These run AFTER binding, so they override appsettings values
options.BasicAuthUsername = Environment.GetEnvironmentVariable("GOTENBERG_USER");
options.BasicAuthPassword = Environment.GetEnvironmentVariable("GOTENBERG_PASS");
});
services.AddGotenbergSharpClient();
```
## Testing
All 9 BasicAuthTests pass, including new tests for:
- Hybrid configuration with PostConfigure overrides
- Programmatic-only configuration
- Incomplete auth validation
0 commit comments