Constructor
# new InjectableRegistryImp()
Holds the various Injectable
s in a cache and provides methods to register, retrieve, and build them.
Default implementation of the InjectablesRegistry interface.
sequenceDiagram
participant Client
participant Registry
Client->>Registry: register(MyService)
Registry->>Registry: Store in cache
Client->>Registry: get("MyService")
alt Instance exists and is singleton
Registry-->>Client: Return cached instance
else No instance or not singleton
Registry->>Registry: build(name)
Registry-->>Client: Return new instance
end
- Implements:
- InjectablesRegistry
Example
// Create a new registry
const registry = new InjectableRegistryImp();
// Register a class
class MyService {
doSomething() {
return 'Hello World';
}
}
registry.register(MyService, 'MyService', true);
// Get the instance
const service = registry.get('MyService');
service.doSomething(); // 'Hello World'