Repository navigation
Commit fd3d94e
feat(di): DI004 — transient IDisposable service-located from the root provider (#65)
The explicit / service-locator form of the transient-disposable leak — the call site
the registration graph (DI001/2/3) cannot see. A singleton that injects an
IServiceProvider (the root container) and resolves a transient IDisposable from it by
hand (GetService<T>() / GetRequiredService<T>()) accumulates instances the root tracks
and disposes only at application shutdown: an unbounded, repeated-at-runtime leak.
Extractor: records per class the injected-IServiceProvider names — ctor params of that
type plus the real class fields assigned from them (in a block- or expression-bodied
ctor, or a field initializer; restricted to declared fields so a local alias can never
same-name-match a receiver) — and reads each resolution off them into a new root_resolves
fact; a scope.ServiceProvider.Get... receiver is deliberately excluded.
Core: find_explicit_root_resolutions walks the resolved type's transient subtree exactly
as DI003 does (entered at the call site, not a ctor edge), so a transient IDisposable
reached directly or through a non-disposable transient wrapper is flagged on a singleton,
surfaced as a warning (DI004) with the full path — a distinct code, not "DI003 explicit"
(different detection, different fix: resolve from an IServiceScope). ownir load() validates
root_resolves as an array of strings.
Precision (0 FP): only singletons; the injected provider, never a scope's; transient ∧
disposable with scoped edges not followed; alias capture restricted to real fields — each
pinned by a silent control in DiCaptiveSample.cs (ScopedResolver / PlainResolver /
RequestResolver). Three flagged shapes are pinned end-to-end by the wpf-extractor CI job
(ConnectionResolver block ctor, ExprBodiedResolver expression-bodied ctor, transitive
WrapperResolver -> MidConnection -> PooledConnection; exactly 3 DI004 + the rendered path;
DI001=4 / DI002=3 / DI003=1 unchanged) and at the graph level by tests/test_ownir.py.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rg8kSk1YT14x7A1vo5zgED1 parent 9f7fd8f commit fd3d94e
8 files changed
Lines changed: 486 additions & 14 deletions
File tree
- .github/workflows
- docs
- notes
- proposals
- frontend/roslyn
- OwnSharp.Extractor
- samples
- ownlang
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
347 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
348 | 376 | | |
349 | 377 | | |
350 | 378 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
122 | 178 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
| |||
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
55 | | - | |
56 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
57 | 75 | | |
58 | 76 | | |
59 | 77 | | |
| |||
82 | 100 | | |
83 | 101 | | |
84 | 102 | | |
85 | | - | |
86 | | - | |
| 103 | + | |
| 104 | + | |
87 | 105 | | |
88 | 106 | | |
89 | 107 | | |
| |||
98 | 116 | | |
99 | 117 | | |
100 | 118 | | |
101 | | - | |
102 | | - | |
103 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
0 commit comments