Procyon|Docs
ComponentsRegistration

Register Constructors

Register constructors so Procyon can create application components.

Registration turns constructor functions into component definitions. A definition contains the component name, scope, return type, constructor metadata, and optional metadata.

user/init.go
package user

import "codnect.io/procyon/component"

func init() {
	component.Register(NewUserRepository)
	component.Register(NewUserService)
}

During startup, Procyon loads registered definitions into the runtime container. The container then creates component instances and resolves constructor arguments from the dependency graph.

Registration flow

  1. Write a constructor.
  2. Register it with component.Register.
  3. Optionally customize the generated definition.
  4. Let the runtime container create the instance.
service.go
type UserService struct {
	repo *UserRepository
}

func NewUserService(repo *UserRepository) *UserService {
	return &UserService{repo: repo}
}

Start with constructor shape, then configure names and scopes when the default definition is not enough.

On this page