https://github.com/vlorc/gioc
golang ioc framework
https://github.com/vlorc/gioc
factory go golang-library inject ioc register
Last synced: 5 months ago
JSON representation
golang ioc framework
- Host: GitHub
- URL: https://github.com/vlorc/gioc
- Owner: vlorc
- License: apache-2.0
- Created: 2017-06-07T03:22:17.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-02-20T13:36:21.000Z (over 5 years ago)
- Last Synced: 2024-06-19T02:05:47.532Z (about 2 years ago)
- Topics: factory, go, golang-library, inject, ioc, register
- Language: Go
- Size: 225 KB
- Stars: 33
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [Gioc](https://github.com/vlorc/gioc)
[简体中文](https://github.com/vlorc/gioc/blob/master/README_CN.md)
[](https://opensource.org/licenses/Apache-2.0)
[](https://codebeat.co/projects/github-com-vlorc-gioc-master)
[](https://goreportcard.com/report/github.com/vlorc/gioc)
[](https://godoc.org/github.com/vlorc/gioc)
[](https://travis-ci.org/vlorc/gioc)
[](https://codecov.io/gh/vlorc/gioc)
gioc is a lightweight Ioc framework,it provides register and factory and depend solution
## Features
* Dependency Resolve
* Dependency Inject
* Singleton/Transient Support
* Custom Tag
* Invoker Support
* [Lazy](https://github.com/vlorc/gioc/blob/master/examples/lazy/main.go) Load
* [Struct](https://github.com/vlorc/gioc/blob/master/examples/depend/main.go) Extends Support
* [Condition](https://github.com/vlorc/gioc/blob/master/examples/cond/main.go) Support
* [Module](https://github.com/vlorc/gioc/blob/master/examples/module/main.go) Support
## Installing
go get -u github.com/vlorc/gioc
## Quick Start
* Create Root Module
```golang
gioc.NewRootModule()
```
* Import Module
```golang
NewModuleFactory(
Import(
ConfigModule,
ServerModule,
)
)
```
* Declare Instance
```golang
NewModuleFactory(
Declare(
Instance(1), Id("id"),
Instance("ioc"), Id("name"),
),
)
```
* Export Instance
```golang
NewModuleFactory(
Export(
Instance(1), Id("id"),
Instance("ioc"), Id("name"),
),
)
```
* Condition Import
```golang
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),
),
)
```
## Examples
* Basic Module
```golang
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)
}),
)
}
```
## License
This project is under the apache License. See the LICENSE file for the full license text.
## Interface
+ 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
# Roadmap
For details on planned features and future direction please refer
to [roadmap](https://github.com/vlorc/gioc/blob/master/ROADMAP.md)
# Keyword
**dependency injection, inversion of control**
# Reference