gioc is a lightweight Ioc framework,it provides register and factory and depend solution
- Dependency Resolve
- Dependency Inject
- Singleton/Transient Support
- Custom Tag
- Invoker Support
- Lazy Load
- Struct Extends Support
- Condition Support
- Module Support
go get -u github.com/vlorc/gioc
- Create Root Module
gioc.NewRootModule()
- Import Module
NewModuleFactory(
Import(
ConfigModule,
ServerModule,
)
)
- Declare Instance
NewModuleFactory(
Declare(
Instance(1), Id("id"),
Instance("ioc"), Id("name"),
),
)
- Export Instance
NewModuleFactory(
Export(
Instance(1), Id("id"),
Instance("ioc"), Id("name"),
),
)
- Condition Import
NewModuleFactory(
Condition(
HavingValue(Equal("redis"), types.StringType, "cache.type"),
Import(RedisModule),
),
Condition(
Or(
Not(HavingBean(types.StringType, "cache.type")),
HavingValue(Equal("memory"), types.StringType, "cache.type"),
),
Import(MemoryModule),
),
)
- Basic Module
import (
."github.com/vlorc/gioc"
."github.com/vlorc/gioc/module"
."github.com/vlorc/gioc/module/operation"
)
// config.go
var ConfigModule = NewModuleFactory(
Export(
Mapping(map[string]interface{}{
"id": 1,
"name": "ioc",
}),
),
)
// main.go
func main() {
NewRootModule(
Import(ConfigModule),
Bootstrap(func(param struct{ id int; name string }) {
println("id: ", param.id, " name: ",param.name)
}),
)
}
This project is under the apache License. See the LICENSE file for the full license text.
- Provider
- provides Factory discovery
- Factory
- responsible for generating Instance
- the basic plant has a value factory, method factory, agent factory, single factory, type factory
- Register
- as a connection to Factory and Selector
- provides the registration method, which eventually matches the Type to the Factory
- Dependency
- for target type dependency analysis, collection integration
- converted to an Injector by an instance
- Container
- provides Register and Provider, and the parent container makes up traversal
- convert to read-only Provider
- convert to seal Container
- Selector
- find factory by type and name
- Module
- import module
- export factory
- declare factory
For details on planned features and future direction please refer to roadmap
dependency injection, inversion of control