Add first-class lazy class registration - #24
Open
kburov-sc wants to merge 1 commit into
Open
Conversation
kburov-sc
marked this pull request as ready for review
August 21, 2026 06:36
Add lazy class-provider overloads across Container, PartialContainer, appendClass, and ClassInjectable while preserving existing eager behavior. Defer class lookup and dependency metadata until first resolution, cache the returned constructor, and retain existing override, self-dependency, retry, and service memoization semantics. Add runtime and type-level coverage, lazy-loader benchmarks and documentation, and bump the library version to 1.1.0.
kburov-sc
force-pushed
the
kburov/lazy-class
branch
from
August 21, 2026 06:40
331d514 to
55a0081
Compare
ecoronadosc
approved these changes
Aug 21, 2026
ecoronadosc
left a comment
Collaborator
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.
Collaborator
Author
|
🤖 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. |
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.
Background
providesClasscurrently reads a class and its dependency metadata while registering the service. With cache-on-first-read module namespaces such as Valdi's lazy export loader, 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)ClassInjectableContainerregistration avoids readingfn.dependenciesuntil resolution.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 118 tests pass with 100% coverage.npm run compilenpm run styleguidenpm run bench