MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / resolve

Function resolve

packages/context/src/resolver.ts:127–164  ·  view source on GitHub ↗

* Resolve the value or promise for a given injection * @param ctx - Context * @param injection - Descriptor of the injection * @param session - Optional session for binding and dependency resolution

(
  ctx: Context,
  injection: Readonly<Injection>,
  session?: ResolutionSession,
)

Source from the content-addressed store, hash-verified

125 * @param session - Optional session for binding and dependency resolution
126 */
127function resolve<T>(
128 ctx: Context,
129 injection: Readonly<Injection>,
130 session?: ResolutionSession,
131): ValueOrPromise<T> {
132 /* istanbul ignore if */
133 if (debug.enabled) {
134 debug(
135 'Resolving an injection:',
136 ResolutionSession.describeInjection(injection),
137 );
138 }
139
140 ctx = resolveContext(ctx, injection, session);
141 const resolved = ResolutionSession.runWithInjection(
142 s => {
143 if (injection.resolve) {
144 // A custom resolve function is provided
145 return injection.resolve(ctx, injection, s);
146 } else {
147 // Default to resolve the value from the context by binding key
148 assert(
149 isBindingAddress(injection.bindingSelector),
150 'The binding selector must be an address (string or BindingKey)',
151 );
152 const key = injection.bindingSelector as BindingAddress;
153 const options: ResolutionOptions = {
154 session: s,
155 ...injection.metadata,
156 };
157 return ctx.getValueOrPromise(key, options);
158 }
159 },
160 injection,
161 session,
162 );
163 return resolved;
164}
165
166/**
167 * Given a function with arguments decorated with `@inject`,

Callers 15

resolveInjectedArgumentsFunction · 0.70
valuesMethod · 0.70
createAppWithShutdownFunction · 0.50
getControllersFunction · 0.50
getControllersFunction · 0.50
_runNpmScriptMethod · 0.50
utils.jsFile · 0.50
test-utils.jsFile · 0.50
gitFunction · 0.50
runNpmScriptFunction · 0.50
constructorMethod · 0.50

Calls 6

isBindingAddressFunction · 0.90
resolveContextFunction · 0.85
describeInjectionMethod · 0.80
runWithInjectionMethod · 0.80
resolveMethod · 0.80
getValueOrPromiseMethod · 0.80

Tested by 15

createAppWithShutdownFunction · 0.40
getControllersFunction · 0.40
getControllersFunction · 0.40
getAppFunction · 0.40
getAppFunction · 0.40
buildAppWithInterceptorsFunction · 0.40
getAppFunction · 0.40
getAppFunction · 0.40
getAppFunction · 0.40
getAppFunction · 0.40
setupSandboxFunction · 0.40
getAppFunction · 0.40