container

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 3 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 is a function that builds a value (lazy). Return T or (T, error).

type Container

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

Container is a simple IoC container: bind name → constructor, resolve with Make (AdonisJS/Laravel style). Supports auto-wiring: constructors whose parameters are interface or pointer types are resolved automatically from the container's type bindings.

func New

func New() *Container

New returns a new container.

func (*Container) Bind

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

Bind registers a constructor for name. Each Make(name) calls the constructor.

func (*Container) Has

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

Has returns true if a binding exists for the given name.

func (*Container) Instance

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

Instance registers a pre-built value directly (no constructor). Subsequent Make calls return this exact value.

c.Instance("stripe", stripeClient)

func (*Container) Make

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

Make resolves name to a value by calling the registered constructor.

func (*Container) MustMake

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

MustMake is like Make but panics on error.

func (*Container) Singleton

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

Singleton registers a constructor that is invoked once; subsequent Make returns the same instance.

Jump to

Keyboard shortcuts

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