(token: Container.Injectable<T>, must = true)
| 48 | inject<T>(token: Container.Injectable<T>, must: false): T | undefined; |
| 49 | |
| 50 | inject<T>(token: Container.Injectable<T>, must = true) { |
| 51 | const entry = this.#registry.get(token); |
| 52 | |
| 53 | if (entry) { |
| 54 | if (entry.singleton) { |
| 55 | if (entry.instance) { |
| 56 | return entry.instance.value; |
| 57 | } |
| 58 | |
| 59 | entry.instance = { value: entry.factory() }; |
| 60 | |
| 61 | return entry.instance.value; |
| 62 | } else { |
| 63 | return entry.factory(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if (must) { |
| 68 | throw new Error(`Dependency with name '${token.name}' could not be resolved.`); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Global container instance |
no test coverage detected