Add DP066 and Autofac coverage to CaptiveDependencyAnalyzer#222
Merged
Conversation
Singleton lifecycle diagnostics P1 (RFC: SingletonLifecycleDiagnostics, ADR-008): - Collect Autofac registrations (RegisterType + fluent lifetime chain, Register delegate) by symbol-name matching with no Autofac package reference, reusing DP062 constructor analysis. - New DP066 (Warning): a Singleton factory delegate (MSDI AddSingleton factory or Autofac Register(...).SingleInstance()) directly resolves a Scoped/Transient service via GetRequiredService/GetService/Resolve. - MSDI factory and instance registrations now feed the lifetime map, so Singletons constructor-depending on factory-registered Scoped or Transient services report DP062 (previously missed). - Suppress RS2002 alongside RS2003: release tracking cannot resolve compile-linked descriptor IDs, so unshipped entries false-positive. - 11 new Verify snapshot tests (Autofac is a test-only dependency of Analyzers.Tests); sync AGENTS.md diagnostics table, ROADMAP next available ID (DP067), CHANGELOG, and plan P1 status.
Skymly
commented
Jul 8, 2026
Skymly
left a comment
Owner
Author
There was a problem hiding this comment.
CI is green (build-test, pack, samples all passed).
Scope & alignment
- P1 matches ADR-008 / the plan: Autofac registration collection via symbol-name matching (no analyzer package reference), DP066 for Singleton factory delegates, and the DP062 lifetime-map gap fix for MSDI factory/instance registrations.
- Module boundary is respected (Analyzers + Diagnostics + tests/docs only).
Implementation notes
SkipConstructorAnalysiscleanly separates lifetime-map participation from constructor analysis for factory/instance registrations.SemanticModelcaptured at collection time for DP066 avoids RS1030 at compilation end.- Autofac fluent-chain lifetime resolution walks intermediate calls (
As<T>(), etc.) correctly. - RS2002 suppression alongside RS2003 is justified given compile-linked descriptors;
AnalyzerReleases.Unshipped.mdis updated for DP066.
Tests
- 11 Verify snapshots cover positive/negative paths for Autofac DP062, MSDI/Autofac DP066, and the scoped-factory DP062 regression.
System.ComponentModelreference added forIServiceProviderin test compilations — good catch.
Follow-ups (non-blocking, already in RFC/plan)
- P2a/P2b/P3 remain open per the plan.
- Factory-delegate analysis limitation (direct
GetRequiredService/GetService/Resolveonly) should land in a Design Doc when P1 merges.
LGTM to merge from my side.
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.
Summary
Singleton lifecycle diagnostics P1 (RFC, ADR-008, Plan) — Analyzers module only.
CaptiveDependencyAnalyzernow collects Autofac registrations (RegisterType<T>()/RegisterType(typeof(T))with fluent lifetime chain resolution —SingleInstance,InstancePerLifetimeScope, defaultInstancePerDependency— andRegister(c => ...)delegates). Autofac methods are matched by containing-namespace symbol check; the analyzer takes no Autofac package reference.AddSingleton<T>(sp => ...)or AutofacRegister(...).SingleInstance()) directly resolves a Scoped/Transient service viaGetRequiredService/GetService/Resolve. Only direct calls in the delegate body are detected (documented limitation).Test plan
As<T>(), negative), DP066 (MSDIGetRequiredService/GetService, AutofacResolve, negatives incl. non-containerResolvemethod), DP062 via scoped factory registrationCitarget (Release): 0 warnings, 657 tests passing