Class

InjectableRegistryImp

injectable-decorators.InjectableRegistryImp()

Constructor

# new InjectableRegistryImp()

Holds the various Injectables 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

View Source registry.ts, line 2

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'