MCPcopy
hub / github.com/nanbingxyz/5ire / inject

Method inject

src/main/internal/container.ts:50–70  ·  view source on GitHub ↗
(token: Container.Injectable<T>, must = true)

Source from the content-addressed store, hash-verified

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

Callers 15

initLegacyDatabaseFunction · 0.80
validateAndGetProxyFunction · 0.80
ModuleContextClass · 0.80
getMCPServerMethod · 0.80
main.tsFile · 0.80
getMainWindowFunction · 0.80
onDeepLinkFunction · 0.80
openSafeExternalFunction · 0.80
PromptManagerBridgeClass · 0.80
DownloaderBridgeClass · 0.80

Calls 1

getMethod · 0.80

Tested by

no test coverage detected