Procyon
Components

Resolve Components

Resolve components manually from a container.

Resolve Components

Most application code should prefer constructor injection. For integration code, you can resolve a component from the current runtime context.

package runner

import (
    "context"

    "codnect.io/procyon/component"
    "codnect.io/procyon/runtime"
)

type ReportRunner struct {
    ctx runtime.Context
}

func NewReportRunner(ctx runtime.Context) *ReportRunner {
    return &ReportRunner{ctx: ctx}
}

func (r *ReportRunner) Run(ctx context.Context) error {
    service, err := component.ResolveType[*ReportService](
        ctx,
        r.ctx.Container(),
    )
    if err != nil {
        return err
    }

    return service.Generate(ctx)
}
HelperUse it for
component.Resolve[T](ctx, container, name)resolving a named component as T
component.ResolveType[T](ctx, container)resolving a component by type
component.ResolveAll[T](ctx, container)resolving every component assignable to T
component.CanResolve(container, name)checking whether a name can resolve
component.CanResolveType[T](container)checking whether a type can resolve

On this page