Procyon|Docs
ComponentsLifecycle

Manage Lifecycle

Run setup, cleanup, and processors around component creation.

Lifecycle hooks run around component creation and shutdown. Use them when a component needs runtime work that does not belong in the constructor.

Constructor:

cache.go
func NewCache(client CacheClient) *Cache {
	return &Cache{client: client}
}

Lifecycle hook:

cache.go
func (c *Cache) Init(ctx context.Context) error {
	return c.client.Ping(ctx)
}

Lifecycle roles

InterfaceUse it for
component.Initializersetup after dependencies are wired
component.Disposablecleanup during application shutdown
component.BeforeInitProcessorcross-cutting work before initialization
component.AfterInitProcessorcross-cutting work after initialization

Keep constructors cheap and deterministic. Put runtime setup and cleanup into lifecycle hooks.

On this page