Support credential instance reuse in WithAzureCredential DI path#56245
Merged
Support credential instance reuse in WithAzureCredential DI path#56245
Conversation
jsquire
approved these changes
Feb 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements credential instance reuse for Azure SDK clients registered via dependency injection with identical credential configurations. By enabling MSAL token cache sharing across clients, it improves application resilience and follows Azure Identity best practices.
Changes:
- Introduced
ConfigurableCredentialCacheto cacheConfigurableCredentialinstances using SHA256-hashed, content-based keys - Modified
WithAzureCredential(IClientBuilder)to leverage per-host caching viaConditionalWeakTable - Added comprehensive test coverage (26 tests) validating cache behavior across various scenarios
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/identity/Azure.Identity/src/ConfigurableCredentialCache.cs | New internal cache class with SHA256-based key generation from configuration sections |
| sdk/identity/Azure.Identity/src/ConfigurationExtensions.cs | Added ConditionalWeakTable-based cache lookup in WithAzureCredential DI overload |
| sdk/identity/Azure.Identity/tests/ConfigurableCredentials/ConfigurableCredentialCacheTests.cs | Unit tests for cache key generation logic (10 tests) |
| sdk/identity/Azure.Identity/tests/ConfigurableCredentials/WithAzureCredentialTests.cs | Integration tests for full DI pipeline credential reuse (16 tests) |
| sdk/identity/Azure.Identity/tests/Azure.Identity.Tests.csproj | Added Microsoft.Extensions.Hosting package reference for tests |
christothes
reviewed
Feb 13, 2026
christothes
reviewed
Feb 13, 2026
christothes
reviewed
Feb 13, 2026
…implify to StringBuilder
…aths with lazy initialization
christothes
approved these changes
Feb 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #56231
What
When multiple Azure clients are registered via DI with identical credential configuration, they now share the same \ConfigurableCredential\ instance. This enables MSAL token cache reuse across clients, improving resilience per Azure Identity best practices.
How
Scope
Only the \WithAzureCredential(IClientBuilder)\ overload (DI path) is changed. The direct \ClientSettings\ overload is unchanged.
Tests