class Wizard {
private injector = inject(Injector);
// Lazily initialize the wand property
private wand?: Wand;
getWand(): Wand {
// An injection context does not exist here, but the
// Injector instance retains and reuse the context
// that was present at the time of its injection
return (this.wand ??= this.injector.inject(Wand));
}
}
Allows performing injections outside the normal injection context window.