Documentation
¶
Index ¶
- Variables
- func Get[T any](ctx context.Context, r Resolver, opts ...KeyOpt) (T, error)
- func GetByKey[T any](ctx context.Context, r Resolver, k Key) (T, error)
- type Appender
- type AsOpt
- type BadCastError
- type BindError
- type Container
- type HookOpt
- type Key
- type KeyOpt
- type Module
- type MultiError
- type NotFoundError
- type Provider
- type RegOpt
- type Registrar
- func Bind[I any](as AsOpt, opts ...RegOpt) Registrar
- func Invoke(fn func(ctx context.Context, r Resolver) error) Registrar
- func OnStart(fn func(ctx context.Context, r Resolver) error, opts ...HookOpt) Registrar
- func OnStartFor[T any](fn func(ctx context.Context, r Resolver, t T) error, opts ...HookOpt) Registrar
- func OnStop(fn func(ctx context.Context, r Resolver) error, opts ...HookOpt) Registrar
- func OnStopFor[T any](fn func(ctx context.Context, r Resolver, t T) error, opts ...HookOpt) Registrar
- func Provide[T any](p Provider[T], opts ...RegOpt) Registrar
- func Set[T any](appenders ...Appender[T]) Registrar
- type Resolver
Constants ¶
This section is empty.
Variables ¶
var ( ErrBindingNotFound = errors.New("binding not found") ErrInvokeFail = errors.New("invoke failed") )
Functions ¶
Types ¶
type AsOpt ¶
type AsOpt struct {
// contains filtered or unexported fields
}
AsOpt encodes a "bind interface to implementation type" choice.
type BadCastError ¶
func (BadCastError) Error ¶
func (e BadCastError) Error() string
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is the runtime DI container built from Modules.
func (*Container) ExportCreationOrderDOT ¶
ExportCreationOrderDOT returns a DOT graph (Graphviz) of the creation order. Rank is left-to-right; edges connect creation sequence.
func (*Container) ExportCreationOrderPlantUML ¶
ExportCreationOrderPlantUML returns a simple PlantUML activity diagram of creation order.
type HookOpt ¶
type HookOpt interface {
// contains filtered or unexported methods
}
func WithPriority ¶
WithPriority assigns a group/priority:
Start: lower values start earlier Stop: higher values stop later (reverse order)
func WithStartTimeout ¶
WithStartTimeout sets a per-hook timeout applied by Container.Start.
func WithStopTimeout ¶
WithStopTimeout sets a per-hook timeout applied by Container.Stop.
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key identifies a dependency by type (and optional name). If typ is a slice, sliceElem holds its element type to speed up set handling.
type KeyOpt ¶
type KeyOpt interface {
// contains filtered or unexported methods
}
KeyOpt modifies the key used to look up a dependency.
type MultiError ¶
type MultiError struct {
// contains filtered or unexported fields
}
MultiError aggregates multiple errors into one.
func IsMultiError ¶
func IsMultiError(err error) (*MultiError, bool)
IsMultiError returns true if the error is a MultiError. It uses errors.As to unwrap the error chain.
func (*MultiError) Append ¶
func (m *MultiError) Append(err error)
func (*MultiError) Error ¶
func (m *MultiError) Error() string
func (*MultiError) Len ¶
func (m *MultiError) Len() int
func (*MultiError) TreeString ¶
func (m *MultiError) TreeString(indent string) string
TreeString renders a simple indented list of aggregated errors.
func (*MultiError) Unwrap ¶
func (m *MultiError) Unwrap() []error
type NotFoundError ¶
func (NotFoundError) Error ¶
func (e NotFoundError) Error() string
type RegOpt ¶
type RegOpt interface {
// contains filtered or unexported methods
}
RegOpt modifies registration behavior.
type Registrar ¶
type Registrar interface {
// contains filtered or unexported methods
}
Registrar mutates a module (registers providers, binds, etc.).
func OnStart ¶
OnStart registers a startup hook executed by Container.Start(ctx). Ordering: priority ASC, then registration/order ASC.
func OnStartFor ¶
func OnStartFor[T any](fn func(ctx context.Context, r Resolver, t T) error, opts ...HookOpt) Registrar
OnStartFor resolves T and passes it to the hook; useful to pre-warm or ping services.
func OnStop ¶
OnStop registers a shutdown hook executed by Container.Stop(ctx). Ordering: priority DESC, then registration/order DESC (reverse).
func OnStopFor ¶
func OnStopFor[T any](fn func(ctx context.Context, r Resolver, t T) error, opts ...HookOpt) Registrar
OnStopFor registers a shutdown hook tied to a specific type T. The hook runs after dependents of T, by ordering using T's creation index (instances created later stop earlier).