You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The instances to be managed by the container are defined in modules. There could be multiple modules organized by the functionality of the instances. Modules are usually placed in a separate package.
A typical module looks like this:
typeExampleModulestruct {
alice.BaseModuleFooFoo`alice:""`BarBar`alice:"Bar"`BazBaz
}
func (m*ExampleModule) InstanceX() X {
returnX{m.Foo}
}
func (m*ExampleModule) InstanceY() Y {
returnY{m.Baz}
}
A module struct must embed the alice.BaseModule struct. It allows 3 types of fields:
Field tagged by alice:"". It will be associated with the same or assignable type of instance defined in other modules.
Field tagged by alice:"Bar". It will be associated with the instance named Bar defined in other modules.
Field without alice tag. It will not be associated with any instance defined in other modules. It is expected to be provided when initializing the module. It is not managed by the container and could not be retrieved.
It is also common that no field is defined in a module struct.
Any public method of the module struct defines one instance to be intialized and maintained by the container. It is required to use a pointer receiver. The method name will be used as the instance name. The return type will be used as the instance type. Inside the method, it could use any field of the module struct to create new instances.
Create container
During the bootstrap of the application, create a container by providing instances of modules.