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

Method createInstance

component/container.go:505–525  ·  view source on GitHub ↗

createInstance constructs a new instance of a component using its definition.

(ctx context.Context, def *Definition)

Source from the content-addressed store, hash-verified

503
504// createInstance constructs a new instance of a component using its definition.
505func (d *DefaultContainer) createInstance(ctx context.Context, def *Definition) (any, error) {
506 constructor := def.Constructor()
507
508 args, err := d.resolveArguments(ctx, constructor.Args())
509 if err != nil {
510 return nil, err
511 }
512
513 var instance any
514 instance, err = constructor.Invoke(args...)
515 if err != nil {
516 return nil, err
517 }
518
519 instance, err = d.initialize(ctx, instance)
520 if err != nil {
521 return nil, err
522 }
523
524 return instance, nil
525}
526
527// createSingleton constructs a singleton instance and registers it in the container.
528// It also handles circular dependency protection via preparation state.

Callers 2

ResolveMethod · 0.95
createSingletonMethod · 0.95

Calls 5

resolveArgumentsMethod · 0.95
initializeMethod · 0.95
ConstructorMethod · 0.80
ArgsMethod · 0.80
InvokeMethod · 0.65

Tested by

no test coverage detected