Documentation ¶
Overview ¶
Package alice provides an additive dependency injection container.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseModule ¶
type BaseModule struct{}
BaseModule is an implementation of Module interface. It should be embedded into each module defined in the application.
A typical module is defined as follows:
type ExampleModule struct { alice.BaseModule Foo Foo `alice:""` // associated by type Bar Bar `alice:"Bar"` // associated by name URL string // not associated. Provided by creating the module. } func (m *ExampleModule) Baz() Baz { return Baz{} }
func (*BaseModule) IsModule ¶
func (b *BaseModule) IsModule() bool
IsModule indicates it is a module.
type Container ¶
type Container interface { // Instance returns an instance by type. It panics when no instance is found, // or multiple instances are found for the same type. Instance(t reflect.Type) interface{} // InstanceByName returns an instance by name. It panics when no instance is found. InstanceByName(name string) interface{} }
Container defines the interface of an instance container. It initializes instances based on dependencies, and provides APIs to retrieve instances by type or name.
func CreateContainer ¶
CreateContainer creates a new instance of container with specified modules. It panics if any of the module is invalid. This is the only way to create a container. Most applications call it only once during bootstrap.