Documentation
¶
Index ¶
- func Get[T any]() (T, error)
- func GetByGroup[T any](group string) ([]T, error)
- func GetGroup[T any](group string) ([]T, error)
- func GetGroupWithCtx[T any](ctx context.Context, group string) ([]T, error)
- func GetInstance[T any]() (T, error)
- func GetWithCtx[T any](ctx context.Context) (T, error)
- func MustGet[T any]() T
- func MustGetInstance[T any]() T
- func Register[T any](creator func() (T, error))
- func RegisterFactory[T any](creator func() (T, error))
- func RegisterGroup[T any](group string, creator func() (T, error))
- func RegisterGroupWithCtx[T any](group string, creator func(context.Context) (T, error))
- func RegisterWithCtx[T any](creator func(context.Context) (T, error))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶ added in v1.0.0
Get retrieves a singleton instance of type T. Returns an error if the instance is not found or type mismatch occurs.
func GetByGroup ¶ added in v1.0.0
GetByGroup is deprecated, use GetGroup instead. Kept for backward compatibility.
func GetGroup ¶ added in v1.0.0
GetGroup retrieves all singleton instances of type T associated with a group.
func GetGroupWithCtx ¶ added in v1.0.0
GetGroupWithCtx retrieves all singleton instances of type T associated with a group with context. The context is passed to creator functions if they accept a context parameter.
func GetInstance ¶
GetInstance is deprecated, use Get instead. Kept for backward compatibility.
func GetWithCtx ¶ added in v1.0.0
GetWithCtx retrieves a singleton instance of type T with context. The context is passed to the creator function if it accepts a context parameter. Returns an error if the instance is not found or type mismatch occurs.
func MustGet ¶ added in v1.0.0
func MustGet[T any]() T
MustGet retrieves a singleton instance of type T, panics on failure. This is useful in init() functions where error handling is not possible.
func MustGetInstance ¶ added in v1.0.0
func MustGetInstance[T any]() T
MustGetInstance is an alias for MustGet, retrieves a singleton instance and panics on failure.
func Register ¶ added in v1.0.0
Register registers a factory function for creating singleton instances of type T. The creator function does not receive a context.
func RegisterFactory ¶
RegisterFactory is deprecated, use Register instead. Kept for backward compatibility.
func RegisterGroup ¶ added in v1.0.0
RegisterGroup registers a factory function and associates it with a group. The creator function does not receive a context.
func RegisterGroupWithCtx ¶ added in v1.0.0
RegisterGroupWithCtx registers a factory function that accepts a context and associates it with a group. The context will be passed when the instance is created.
Types ¶
This section is empty.