Class: InjectionToken
@react-logic/diDefined in: di/src/lib/injection-token.ts:33
An opaque, type-tagged identity used to register and resolve a dependency in the DI container.
Use an InjectionToken when the dependency has no class identity:
configuration strings, primitive values, plain function callbacks,
environment-specific objects, etc. For dependencies that are classes,
the class itself doubles as the token — no InjectionToken is needed.
Each InjectionToken instance is unique by reference. The description
is for debugging only — two tokens constructed with the same description
are different tokens. Token identity is what makes provide/inject
pairs match.
Example
export const API_URL = new InjectionToken<string>('API_URL');
// Provide a value for it…
<Injector provide={[{ provide: API_URL, useValue: 'https://api.test' }]}>
<App />
</Injector>
// …then inject inside any logic class:
class ApiClient {
url = inject(API_URL);
}
Type Parameters
T
T
The type that consumers receive when injecting this token.
Phantom-only — the runtime value carries no T.
Constructors
Constructor
new InjectionToken<
T>(description?):InjectionToken<T>
Defined in: di/src/lib/injection-token.ts:38
Parameters
description?
string = 'unnamed'
Returns
InjectionToken<T>
Properties
description
description:
string='unnamed'
Defined in: di/src/lib/injection-token.ts:38
Methods
toString()
toString():
string
Defined in: di/src/lib/injection-token.ts:41
Returns
string