Commit 43214e3
Address review: keep zero-arg public factory calls working
Before PR #19 the public Container.factories map held memoized factories
that carried a `thisArg`, so calling `c.factories.svc()` directly (without
going through `get()`) would still resolve dependencies through the
container. After the chain switch the factory body uses call-site `this`,
which means a direct invocation makes `this` the factories map itself —
`this.get(...)` then throws for any service with dependencies.
Fix in `buildFlatFactories`: when materializing the public flat view, wrap
each factory in a tiny forwarder that calls the underlying memoized
factory with the container as `this`. Memo state stays in the underlying
factory's closure (so memoization is preserved and shared across the
chain), and both `get()` and a direct `c.factories[token]()` now route
through the same container — matching the old public contract.
Adds a test that exercises a dependent service through the public
factories map. 97/97 tests pass, 100% coverage.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 1a96aef commit 43214e3
2 files changed
Lines changed: 20 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| 303 | + | |
303 | 304 | | |
304 | | - | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
305 | 315 | | |
306 | 316 | | |
307 | 317 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
576 | 576 | | |
577 | 577 | | |
578 | 578 | | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
579 | 588 | | |
580 | 589 | | |
581 | 590 | | |
| |||
0 commit comments