provider

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package provider implements lazy initialization and validation for service instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider[T any, K Validatable] struct {
	// contains filtered or unexported fields
}

Provider manages lazy initialization of service instances with validation support. It ensures thread-safe, single initialization using sync.Once.

func New

func New[T any, K Validatable](
	factory func(cfg K) (T, error),
	cfg K,
	validationContext validation.Context,
) *Provider[T, K]

New creates a Provider with the given factory function, configuration, and validation context. The factory is called lazily on the first Get() invocation.

func (*Provider[T, K]) Get

func (p *Provider[T, K]) Get() (T, error)

Get returns the service instance, validating the config and initializing the service instance on first call. Subsequent calls return the cached instance. Thread-safe.

func (*Provider[T, K]) Validate

func (p *Provider[T, K]) Validate() error

Validate delegates to the configuration's Validate method.

type Validatable

type Validatable interface {
	Validate(validation.Context) error
}

Validatable defines the interface for configuration types that can be validated.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL