Isolate JwtSecurityTokenHandler from consumer DI container#27
Conversation
Co-authored-by: jeanlrnt <63308635+jeanlrnt@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors the DI registration to isolate JwtSecurityTokenHandler from the consumer's dependency injection container, preventing configuration conflicts with other JWT libraries (JwtBearer, IdentityServer, OpenIddict).
- Removed global
JwtSecurityTokenHandlersingleton registration - Implemented factory-based registration for
IMiniJwtServicewith local handler instantiation - Added TimeProvider resolution with fallback to
TimeProvider.System
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/MiniJwt.Core/Extensions/ServiceCollectionExtensions.cs | Replaced direct handler registration with factory pattern that creates a local JwtSecurityTokenHandler instance exclusively for MiniJwtService |
| src/MiniJwt.Tests/MiniJwtTests.Extension.cs | Added test to verify JwtSecurityTokenHandler is not globally resolvable while IMiniJwtService remains functional |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Update documentation with lasts changes @copilot |
Co-authored-by: jeanlrnt <63308635+jeanlrnt@users.noreply.github.com>
Updated all documentation files to reflect the new factory-based DI registration pattern in commit ac28076. Changes:
All examples now show the recommended |
Refactor DI registration to isolate JwtSecurityTokenHandler
Plan:
services.AddSingleton(new JwtSecurityTokenHandler...)fromServiceCollectionExtensions.csIMiniJwtServiceregistration to use factory pattern that creates localJwtSecurityTokenHandlerinstanceTimeProviderresolution logic with fallback toTimeProvider.SystemOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.