ComponentsResolving Components
Resolve by Type
Resolve a single component using its Go type.
Use component.ResolveType when the type uniquely identifies the dependency.
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)
}This is useful when a runtime boundary needs one concrete service and that type has exactly one registered component.
Check before resolving
Use component.CanResolveType when a dependency is optional.
if !component.CanResolveType[*ReportService](container) {
return nil
}If the dependency is required, resolve directly and return the error.
