Procyon|Docs
ComponentsDependency Injection

Qualifiers

Select a named component for a constructor argument.

Use qualifiers when multiple components can satisfy the same constructor parameter type.

mail.go
func init() {
	component.Register(NewPrimaryMailer, component.WithName("primaryMailer"))
	component.Register(NewAuditMailer, component.WithName("auditMailer"))

	component.Register(
		NewNotificationService,
		component.WithQualifierFor[Mailer]("primaryMailer"),
	)
}

component.WithQualifierFor[T] applies a component name to constructor arguments of type T.

Repeated parameter types

When the same type appears more than once, qualify by index.

relay.go
component.Register(
	NewRelayService,
	component.WithQualifierAt(0, "primaryMailer"),
	component.WithQualifierAt(1, "auditMailer"),
)

Qualifier guidance

  • Qualify only when type resolution is ambiguous.
  • Prefer WithQualifierFor[T] when the constructor has one parameter of that type.
  • Use WithQualifierAt when the same parameter type appears multiple times.
  • Keep component names stable because qualifiers depend on them.