MCPcopy Create free account
hub / github.com/esengine/esengine / resolve

Method resolve

packages/fairygui/src/core/ServiceContainer.ts:118–149  ·  view source on GitHub ↗

* Resolve a service * 解析服务

(identifier: ServiceIdentifier<T>)

Source from the content-addressed store, hash-verified

116 * 解析服务
117 */
118 public resolve<T>(identifier: ServiceIdentifier<T>): T {
119 this.checkDisposed();
120
121 const registration = this._registrations.get(identifier);
122 if (!registration) {
123 throw new Error(`Service not registered: ${identifier.name}`);
124 }
125
126 // Check for circular dependency
127 if (this._resolving.has(identifier)) {
128 throw new Error(`Circular dependency detected: ${identifier.name}`);
129 }
130
131 // Return cached singleton if available
132 if (registration.lifecycle === EServiceLifecycle.Singleton && registration.instance !== undefined) {
133 return registration.instance as T;
134 }
135
136 // Resolve
137 this._resolving.add(identifier);
138 try {
139 const instance = registration.factory(this) as T;
140
141 if (registration.lifecycle === EServiceLifecycle.Singleton) {
142 registration.instance = instance;
143 }
144
145 return instance;
146 } finally {
147 this._resolving.delete(identifier);
148 }
149 }
150
151 /**
152 * Try to resolve a service, returns null if not found

Callers 1

tryResolveMethod · 0.95

Calls 5

checkDisposedMethod · 0.95
getMethod · 0.65
hasMethod · 0.65
deleteMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected