createInstance constructs a new instance of a component using its definition.
(ctx context.Context, def *Definition)
| 503 | |
| 504 | // createInstance constructs a new instance of a component using its definition. |
| 505 | func (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. |
no test coverage detected