Inversify Binding Decorators is a utility library for InversifyJS, a powerful Inversion of Control (IoC) container for TypeScript and JavaScript applications. It simplifies the process of declaring dependency injection bindings by allowing developers to use ES2016 decorators directly on classes. This contrasts with InversifyJS's standard fluent API for binding. The current stable version is 4.0.0, which typically aligns with major versions of InversifyJS itself, indicating a release cadence tied to its core dependency. Its primary differentiator is the `@provide` decorator, enabling a more declarative and less verbose way to register components with the InversifyJS container, particularly useful in large applications with many services.
npm install inversify-binding-decoratorsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use the `@provide` decorator to declare bindings and `buildProviderModule` to load them into an InversifyJS container.
Always check the compatibility matrix between `inversify` and `inversify-binding-decorators` before upgrading either package. Review both packages' release notes for breaking changes.
If multiple bindings for the same class are intended, pass `true` as the second argument to `@provide`, e.g., `@provide("Ninja", true)` for multiple identifiers.Ensure `import "reflect-metadata";` is present at the very top of your main application file (e.g., `main.ts`, `app.ts`).
If you intend to provide the class under multiple identifiers, use `@provide(identifier, true)` for each additional binding. For example, `@provide("Logger", true)` and `@provide("ConsoleLogger", true)`.Ensure that any class decorated with `@provide` also has the `@injectable()` decorator from `inversify` applied to it, e.g., `@injectable()
@provide(MyService)
class MyService { ... }`.