Skip to content

Ignore Dispose on the process-wide Instance [patch] - #202

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/201-singleton-ignores-dispose
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/201-singleton-ignores-dispose

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #201

What changed

This takes option 1 from the triage: the singleton ignores Dispose() from outside.

  • The cache that Instance builds is flagged as the singleton, and its Dispose() does nothing. Writing using var cache = CredentialCache.Instance; no longer breaks credential access for the rest of the process. It keeps its cache, and ConfigureStore still refuses to replace it, so "one cache per process" stays true.
  • ResetSingletonForTesting still disposes the old singleton, through a private DisposeCore.
  • A cache created with new CredentialCache(store) disposes as before.
  • The Instance and Dispose XML docs now say what disposing the singleton does.

Tests

  • DisposingTheSingletonLeavesItUsable is the repro from the issue. After a using on Instance, TryGet returns both the cached credential and one that exists only in the store, AddOrReplace works, and ConfigureStore still throws. It fails without the fix.
  • ResetSingletonForTestingStillDisposesTheOldSingleton and DisposingAnOwnedCacheStillDisposesIt guard the disposal paths that are meant to keep working.

The full suite passes: 83 passed, 5 skipped (platform-specific), 0 failed.

The fix won't reach NuGet until #200 (pack failing package validation) is resolved. That is separate from this change.


Generated by Claude Code

Disposing what CredentialCache.Instance returned (easy to do with
`using var cache = CredentialCache.Instance;`, since the same type is
disposable when you new it) left the singleton disposed for the rest of the
process: Instance kept returning it, every method threw
ObjectDisposedException, and ConfigureStore refused to replace it.

The cache Instance builds now ignores Dispose, so it stays usable for every
other component. ResetSingletonForTesting still disposes it, and a cache
created with the constructor disposes as before. The Instance and Dispose
docs say so.

Fixes #201

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5wqHMdBMn6Wino1eH
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants