Repository navigation
Fixes class registration in Container: the shorthand forms now inject static deps, registerClass(X) registers under the class itself, and singletons that resolve to undefined are cached.
npm install syrinject@2.0.0⚠️ Breaking change
registerClass(X) now uses the class X as the token instead of the string X.name.
container.registerClass(UserService, { singleton: true });
container.resolve(UserService); // ✅ 2.0.0
container.resolve("UserService"); // ❌ throws DependencyNotFoundError in 2.0.0The old string token made resolve(UserService) fail, changed under minification (class a) and collided for two classes with the same name. If you resolve by name today, switch to the class, or register the string token explicitly: container.register("UserService", UserService).
Fixes
-
Shorthand registration now reads
static deps.register(X, X, options)andregisterClass(X, options)ignored the class's staticdeps/dependenciesand the constructor receivedundefined. They now fall back to them whenoptions.depsis not given. Explicitoptions.depsstill takes priority.class UserService { static deps = [LoggerToken]; constructor(private readonly logger: LoggerService) {} } container.register(UserService, UserService, { singleton: true }); // logger is injected
-
Singletons resolving to
undefinedare created once. A singleton factory or class whose value isundefinedwas rebuilt on everyresolve. It is now cached like any other value.
The provider form register(X, { useClass: X, ... }) was not affected and behaves the same.
Docs
- README documents the shorthand
register(token, Class, options?)form and the newregisterClasstoken. - Added
CHANGELOG.md.
Full diff: v1.0.0...v2.0.0 · PR #1