Documentation
¶
Overview ¶
Package whyor is a compile-time dependency injection toolkit.
Injectors are declared in files guarded by the "whyor" build tag:
//go:build whyor
func InitApp(path string) (*App, func(), error) {
panic(whyor.Build(NewConfig, NewDB, whyor.Bind[Store, *PG]()))
}
`whyor gen` then writes a whyor_gen.go file containing plain Go code. Nothing in this package does any work at runtime.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option any
Option is a provider, a Set, a Bind or a Value accepted by Build and Set. Plain provider functions are accepted too.
func AutoBind ¶
AutoBind makes T usable wherever an interface it implements is needed, as long as exactly one registered AutoBind type implements that interface.
func Closer ¶
Closer registers T's Close method as its cleanup: the injector must then return a func(). It applies to providers of T that have no cleanup of their own.
func FieldsOf ¶ added in v0.2.0
FieldsOf provides the named fields of T (a struct or pointer to struct) as dependencies of their own types.
func Many ¶
Many provides a []T made of the given providers, each returning a value assignable to T. Its elements are not provided as T on their own.