Add first-class lazy class registration - #24
Conversation
331d514 to
55a0081
Compare
ecoronadosc
left a comment
There was a problem hiding this comment.
This looks good to me.
I would add a caveat somewhere that this is beneficial for lazy evaluated module loaders, but the common web ones may not be.. however having it is a win regardless.
|
🤖 From AI Assistant — Review 4996399000: This caveat is documented in the README’s “Lazy Class Lookup” section, which contrasts Valdi-style lazy export lookup with ordinary static ESM evaluation. The benchmark results also call out that already-loaded/static ESM classes do not show a general performance win. |
|
@kburov-sc I'm conviced that the new class-provider API could be useful not jsut for Valdi :) Could |
55a0081 to
daf821f
Compare
|
🤖 From AI Assistant — iteration history Round 1 — daf821f — Unified lazy dependency resolution
Round 2 — f6b58f8 — Generalized lazy-loader documentation Reframed the README and benchmark documentation around cache-on-first-read module namespaces and lazy export loaders, removing loader-specific coupling while retaining the static ESM caveat. Revalidated Jest, compilation, and style checks. |
|
🤖 From AI Assistant — Implemented in daf821f. For normal |
msilivonik-sc
left a comment
There was a problem hiding this comment.
question about valdi
| The thunk form defers class lookup through `Container` and `PartialContainer` registration and composition until the | ||
| service is first resolved. `appendClass("plugins", () => Plugin)` supports the same form. | ||
|
|
||
| This is especially useful with lazy module loaders such as Valdi, where reading an export from a module namespace can |
There was a problem hiding this comment.
do we want to mention in readme anything about valdi? I feel we started to couple the package to valdi and I don't like that direction. Can we do a cleanup and remove Valdi references?
There was a problem hiding this comment.
🤖 From AI Assistant — Removed the Valdi-specific wording from the README, benchmark methodology/results, benchmark source comment, and PR description. They now describe the behavior generically in terms of cache-on-first-read module namespaces and lazy export loaders. The API and benchmark remain loader-agnostic; this is documentation/comment cleanup only, and the static ESM caveat remains.
daf821f to
f6b58f8
Compare
Background
providesClasscurrently reads a class and its dependency metadata while registering the service. With cache-on-first-read module namespaces, that lookup can evaluate modules even when the service is never resolved.This adds a thunk form that defers class lookup until first resolution while preserving the existing direct-class API and its eager runtime behavior. The thunk defers ts-inject's lookup; it cannot defer evaluation of an ordinary static ESM import, because native ESM evaluates imports before registration code runs.
Change
Container.providesClass("service", () => Service)PartialContainer.providesClass("service", () => Service)appendClass("services", () => Service)ClassInjectableContainerreads injectable dependency metadata on first resolution, allowing lazy classes to use the normal service-resolution path.npm run benchwith 10, 100, and 1,000-class chains.benchmarks/LAZY_CLASS_RESULTS.md.get()performance remains effectively unchanged; ordinary already-loaded classes do not show a general performance win.1.0.1to1.1.0for the additive API release.Test Plan
npm test -- --runInBand— 6 suites and 119 tests pass with 100% coverage.npm run compilenpm run styleguidenpm run bench