component

package
v0.2.19 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ReservedPrefix defines identifiers owned by the system.
	ReservedPrefix = "_"
	// DefaultName defines the name of the default component instance.
	DefaultName = "_default"
)

Variables

View Source
var (
	// ErrRequirementNotFound is returned when a requested requirement is not found.
	ErrRequirementNotFound = errors.New("engine: requirement not found")
)

Functions

This section is empty.

Types

type Category

type Category string

type ConfigEntry

type ConfigEntry struct {
	Name                string
	Value               any
	RequirementResolver RequirementResolver
}

ConfigEntry represents the configuration for a single component instance. RequirementResolver at this level takes precedence over the ModuleConfig level.

type ConfigResolver

type ConfigResolver func(ctx context.Context, source any, opts *LoadOptions) (*ModuleConfig, error)

ConfigResolver resolves raw configuration source into ModuleConfig.

type Container

type Container interface {
	Register(cat Category, p Provider, opts ...RegisterOption)
	Inject(cat Category, name string, inst any, opts ...RegisterOption)
	IsRegistered(cat Category, opts ...RegisterOption) bool
	Requirement(cat Category, purpose string, res RequirementResolver)
	Load(ctx context.Context, source any, opts ...LoadOption) error
	In(cat Category, opts ...InOption) Registry
}

type Handle

type Handle interface {
	Config() any
	Name() string
	Category() Category
	Scope() Scope
	Locator() Locator
	Tag() string // Returns the SINGLE IDENTITY currently being processed by the provider
	Require(purpose string) (any, error)
}

type InOption

type InOption func(Registry) Registry

InOption is a functional option that modifies a Registry.

type LoadOption

type LoadOption func(*LoadOptions)

type LoadOptions

type LoadOptions struct {
	Category Category
	Scope    Scope
	Name     string
	Tags     []string
	Resolver ConfigResolver
}

type Locator

type Locator interface {
	Get(ctx context.Context, name string) (any, error)
	Iter(ctx context.Context) iterator.Iterator
	In(cat Category, opts ...InOption) Registry
	WithInScope(s Scope) Locator
	WithInTags(tags ...string) Locator
	Skip(names ...string) Locator
	Category() Category
	Scope() Scope
	Scopes() []Scope
	Tags() []string // Returns the "Package" of identities carried by this locator
}

type ModuleConfig

type ModuleConfig struct {
	Entries             []ConfigEntry
	Active              string
	RequirementResolver RequirementResolver
}

ModuleConfig represents the configuration for an entire category. RequirementResolver at this level acts as a default for all entries in the category.

type Priority

type Priority int
const (
	// PriorityFramework is the lowest priority, used for framework-level defaults.
	PriorityFramework Priority = 0
	// PriorityInfrastructure is used for common infrastructure (DB, Cache, etc).
	PriorityInfrastructure Priority = 100
	// PriorityDefault is the standard priority for business components.
	PriorityDefault Priority = 200
	// PriorityImportant is used for components that should override defaults.
	PriorityImportant Priority = 300
	// PriorityCritical is the highest priority, for emergency overrides.
	PriorityCritical Priority = 400
)

type Provider

type Provider func(ctx context.Context, h Handle) (any, error)

type RegisterOption

type RegisterOption func(*RegistrationOptions)

type Registration

type Registration struct {
	Category Category
	Provider Provider
	Options  []RegisterOption
}

type RegistrationOptions

type RegistrationOptions struct {
	Scopes              []Scope
	Tag                 string
	Priority            Priority
	DefaultEntries      []string
	ConfigResolver      ConfigResolver
	RequirementResolver RequirementResolver
}

type Registry

type Registry interface {
	Locator
	Register(p Provider, opts ...RegisterOption)
	Inject(name string, inst any, opts ...RegisterOption)
	IsRegistered(opts ...RegisterOption) bool
	Requirement(purpose string, resolver RequirementResolver)
}

type RequirementResolver

type RequirementResolver func(ctx context.Context, h Handle, purpose string) (any, error)

type Scope

type Scope string

Jump to

Keyboard shortcuts

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