box

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 9 Imported by: 0

README

Box

a dependency injection library

Usage

b := box.New()

// put some things in the box
b.Put(&ServiceA{}, &ServiceB{})

// get something out of the box
box.Get[*ServiceA](b)

Benchmarks

  • coming soon!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get[T any](box *Box) T

func GetOrDefault

func GetOrDefault[T any](box *Box, defaultValue T) T

func GetPath

func GetPath[T any](box *Box, path ...string) T

Types

type Box

type Box struct {
	context.Context
	// contains filtered or unexported fields
}

func New

func New() *Box

func (*Box) Deadline

func (self *Box) Deadline() (deadline time.Time, ok bool)

func (*Box) Done

func (self *Box) Done() <-chan struct{}

func (*Box) Err

func (self *Box) Err() error

func (*Box) Fork

func (self *Box) Fork() *Box

func (*Box) Inject

func (self *Box) Inject(handler any) (func() (any, error), error)

func (*Box) Items

func (self *Box) Items() iter.Seq2[string, any]

func (*Box) Keys

func (self *Box) Keys() iter.Seq[string]

func (*Box) Len

func (self *Box) Len() int

func (*Box) MarshalJSON

func (self *Box) MarshalJSON() ([]byte, error)

func (*Box) Merge

func (self *Box) Merge(box *Box)

func (*Box) Put

func (self *Box) Put(values ...any)

func (*Box) PutByKey

func (self *Box) PutByKey(key string, value any)

func (*Box) String

func (self *Box) String() string

func (*Box) Value

func (self *Box) Value(key any) any

func (*Box) Values

func (self *Box) Values() iter.Seq[any]

Jump to

Keyboard shortcuts

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