Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ContextKey is the key used to store the container in the context. ContextKey = &struct{ name string }{name: "di.container.ContextKey"} )
Functions ¶
func Invoke ¶
Invoke Get a value from the map for a key, or panic if none exists. if need all type of T, please use Invoke[Set[T]](ctx)
func SimpleContext ¶
SimpleContext create a context with a simple container objects can be any type, but must be unique. and the type of objects will be used as the key of the container. usage: ctx := SimpleContext(context.Background(), &MyService{})
ctx := SimpleContext(context.Background(), &MyService{}, &MyOtherService{})
ctx := SimpleContext(context.Background(), &MyService{}, &MyOtherService{}, Set[MyInterface]{&MyService{}, &MyOtherService{}})
Types ¶
type Interface ¶
type Interface interface { // Invoke Get a value from the map for a key, or panic if the key does not exist. Invoke(ctx context.Context, typ reflect.Type) any }
Interface Container interface
type Set ¶
type Set[T any] []T
Set is used to return a set of instances for a particular type. This is used to inform the Container that it should return a set of instances (as opposed to a single instance) for the specified type. usage: Invoke[Set[MyInterface]](ctx) Note that this feature depends on the container implementation. If the container allows to register multiple objects of the same type, then Invoke[Set[MyInterface]](ctx) will return all objects of the same type.