registerar

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Binding

type Binding struct {
	// contains filtered or unexported fields
}

Binding holds a resolver and a concrete (if already resolved). It is the break for the Container wall!

func NewBinding

func NewBinding(
	name string,
	isSingleton bool,
	bindParams []reflect.Value,
	namedBindings []string,
	resolver any,
	concrete any,
) *Binding

NewBinding creates and returns a new Binding instance.

func (*Binding) BindParams

func (b *Binding) BindParams() []reflect.Value

BindParams returns the parameters specified at bind time for dependency resolution.

func (*Binding) Dependencies added in v1.2.0

func (b *Binding) Dependencies() []reflect.Type

Dependencies returns the resolver inputs left unsatisfied by the parameters given at bind time, worked out once since neither of the two ever changes.

func (*Binding) DependencyNames added in v1.2.0

func (b *Binding) DependencyNames() iter.Seq[string]

DependencyNames yields the names to look a dependency up under, in the order the container tries them.

func (*Binding) GetName

func (b *Binding) GetName() string

GetName returns the name of the Binding.

func (*Binding) GetOrSetConcrete

func (b *Binding) GetOrSetConcrete(
	factory func(b *Binding, params []reflect.Value) (any, error),
	params []reflect.Value,
) (any, error)

GetOrSetConcrete returns the existing concrete if set, otherwise calls factory exactly once to create it. Safe for concurrent use.

func (*Binding) HasConcrete

func (b *Binding) HasConcrete() bool

HasConcrete checks if the Binding has a concrete instance.

func (*Binding) IsSingleton

func (b *Binding) IsSingleton() bool

IsSingleton specifies whether the Binding is a singleton.

func (*Binding) NamedBindings

func (b *Binding) NamedBindings() []string

NamedBindings returns the named Bindings specified at bind time for dependency resolution.

func (*Binding) Resolver

func (b *Binding) Resolver() any

Resolver returns the resolver function of the Binding.

type Registrar

type Registrar struct {
	// contains filtered or unexported fields
}

Registrar manages binding registerations. It is the way in to the store holding them and to the acyclic guard deciding what may join it, and owns the lock the two are used under.

func NewRegisterar

func NewRegisterar() *Registrar

NewRegisterar creates and returns a new Registrar instance.

func (*Registrar) Delete

func (r *Registrar) Delete(t reflect.Type, name string)

Delete removes the binding by exact type match.

func (*Registrar) Find

func (r *Registrar) Find(abstraction reflect.Type, name string) (*Binding, bool)

Find retrieves a binding by exact type match, falling back to interface-implementation lookup.

func (*Registrar) FindSlot added in v1.2.0

func (r *Registrar) FindSlot(abstraction reflect.Type, name string) (Slot, bool)

FindSlot is like Find but returns the slot holding the match instead of the binding.

func (*Registrar) Get

func (r *Registrar) Get(t reflect.Type, name string) (*Binding, bool)

Get retrieves a binding by exact type match.

func (*Registrar) Registrations added in v1.2.0

func (r *Registrar) Registrations() []Registration

Registrations returns a snapshot of every registration, in the order the slots were first registered.

func (*Registrar) Reset

func (r *Registrar) Reset()

Reset clears all bindings.

func (*Registrar) Set

func (r *Registrar) Set(t reflect.Type, name string, b *Binding) error

Set stores the binding, refusing it when the registration would introduce a circular dependency.

func (*Registrar) SetIfAbsent

func (r *Registrar) SetIfAbsent(t reflect.Type, name string, b *Binding) (wasNew bool, err error)

SetIfAbsent is like Set but only stores b when the slot is currently empty. Returns wasNew=true if b was stored, false if the slot was already taken.

type Registration added in v1.2.0

type Registration struct {
	Slot    Slot
	Binding *Binding
}

Registration pairs a binding with the slot it is registered in.

type Slot added in v1.2.0

type Slot struct {
	Type reflect.Type
	Name string
}

Slot identifies a registration: the type a binding produces plus its name.

func (Slot) String added in v1.2.0

func (s Slot) String() string

String renders the Slot as `main.Shape`, or `main.Shape("cache")` when it is named.

Jump to

Keyboard shortcuts

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