Procyon|Docs
ComponentsDependency Injection

Wire Dependencies

Express component dependencies through constructor parameters.

Constructor parameters are resolved from the container. This makes the component graph visible at startup and keeps dependencies out of package-level globals.

service.go
func NewWelcomeService(mailer Mailer) *WelcomeService {
	return &WelcomeService{mailer: mailer}
}

If exactly one component is assignable to Mailer, Procyon injects it automatically.

Wiring flow

  1. Register dependency constructors.
  2. Register the dependent constructor.
  3. The container resolves constructor arguments by type.
  4. Qualifiers select a named dependency when type alone is ambiguous.

Use constructor injection first. Add interface boundaries and qualifiers only when the graph needs them.

On this page