registerar

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 3 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) Concrete

func (b *Binding) Concrete() any

Concrete returns the concrete instance of the Binding if it is a singleton and has been resolved, otherwise it returns nil.

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) HasName

func (b *Binding) HasName() bool

HasName specifies whether the Binding has a name.

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.

func (*Binding) SetConcrete

func (b *Binding) SetConcrete(concrete any)

SetConcrete sets the concrete instance of the Binding. Safe for concurrent use.

type Registrar

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

Registrar manages binding registerations.

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) Get

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

Get retrieves a binding by exact type match.

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 checks for a circular dependency and, if none is found, atomically stores the binding.

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.

Jump to

Keyboard shortcuts

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