container

package
v1.15.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Constructor

type Constructor any

Constructor builds a value lazily. Return T or (T, error).

type Container

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

Container registers constructors by name and auto-wires their parameters. Registry locks never cover user constructors. Concurrent singleton resolution shares one construction per binding; independent bindings can build in parallel.

func New

func New() *Container

func (*Container) Bind

func (c *Container) Bind(name string, f Constructor)

Bind registers a constructor called for each Make.

func (*Container) Has

func (c *Container) Has(name string) bool

func (*Container) Instance

func (c *Container) Instance(name string, value any)

Instance registers a pre-built value.

func (*Container) Make

func (c *Container) Make(name string) (any, error)

Make resolves a binding. Declared dependency cycles and ambiguous interface bindings return errors. Constructors may resolve independent bindings via Make; recursive cycles hidden inside constructor bodies must be avoided.

func (*Container) MustMake

func (c *Container) MustMake(name string) any

func (*Container) Singleton

func (c *Container) Singleton(name string, f Constructor)

Singleton registers a constructor whose successful result is shared.

Jump to

Keyboard shortcuts

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