MCPcopy Create free account
hub / github.com/codnect/procyon / ResolveType

Method ResolveType

component/container.go:348–377  ·  view source on GitHub ↗

ResolveType retrieves an instance of the specified type.

(ctx context.Context, typ reflect.Type)

Source from the content-addressed store, hash-verified

346
347// ResolveType retrieves an instance of the specified type.
348func (d *DefaultContainer) ResolveType(ctx context.Context, typ reflect.Type) (any, error) {
349 if typ == nil {
350 return nil, errors.New("nil type")
351 }
352
353 ctx = withCreationState(ctx)
354
355 resolvableCandidates := d.findResolvableCandidates(typ)
356 if len(resolvableCandidates) > 1 {
357 return nil, errors.New("multiple instance found")
358 } else if len(resolvableCandidates) == 1 {
359 return resolvableCandidates[0], nil
360 }
361
362 singletons := d.resolveSingletons(typ)
363 if len(singletons) > 1 {
364 return nil, errors.New("multiple singletons found")
365 } else if len(singletons) == 1 {
366 return singletons[0], nil
367 }
368
369 definitions := d.DefinitionsOf(typ)
370 if len(definitions) > 1 {
371 return nil, errors.New("multiple definitions found")
372 } else if len(definitions) == 1 {
373 return d.Resolve(ctx, definitions[0].Name())
374 }
375
376 return nil, ErrInstanceNotFound
377}
378
379// ResolveAs retrieves a component by both name and expected type.
380func (d *DefaultContainer) ResolveAs(ctx context.Context, name string, typ reflect.Type) (any, error) {

Callers 2

resolveArgumentsMethod · 0.95

Calls 6

resolveSingletonsMethod · 0.95
DefinitionsOfMethod · 0.95
ResolveMethod · 0.95
withCreationStateFunction · 0.85
NameMethod · 0.65

Tested by 1