(Proxy Based Injection pronounced 🫛Pea 🐝Bee And 🐦Jay)
A lightweight, proxy-based Dependency Injection (DI) framework for Node.js with full TypeScript support.
- 🪶 Lightweight with zero runtime dependencies (other than
node:async_hooks) - 🔄 Proxy-based lazy loading of dependencies
- 📦 Type-safe with full TypeScript support
- 🎯 No decorators required
- 🏗️ Supports constructor injection, factory injection, and primitive injection
- 💾 Built-in caching support
Using npm:
npm install @pbinj/pbjUsing yarn:
yarn add @pbinj/pbjUsing pnpm:
pnpm add @pbinj/pbjimport { pbj, context } from "@pbinj/pbj";
// Define a service
class DatabaseService {
connect() {
console.log("Connected to database");
}
}
// Register the service
context.register(DatabaseService);
// Use the service
class UserService {
constructor(private db = pbj(DatabaseService)) {}
getUsers() {
this.db.connect();
// ... fetch users
}
}
const userService = context.resolve(UserService);
userService.getUsers(); // Outputs: Connected to database- Node.js >= 18
- TypeScript (for type support)
For detailed documentation, examples, and advanced usage, visit our documentation site.
MIT
