Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deatil/go-container
go-container is a container pkg for go
https://github.com/deatil/go-container
container di go-container go-di go-ioc ioc
Last synced: about 1 month ago
JSON representation
go-container is a container pkg for go
- Host: GitHub
- URL: https://github.com/deatil/go-container
- Owner: deatil
- License: apache-2.0
- Created: 2024-07-31T11:07:02.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-29T04:35:58.000Z (4 months ago)
- Last Synced: 2024-10-12T11:27:39.477Z (2 months ago)
- Topics: container, di, go-container, go-di, go-ioc, ioc
- Language: Go
- Homepage: https://pkg.go.dev/github.com/deatil/go-container
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## go-container
### Desc
* go-container is a container pkg for go.
[中文](README_CN.md) | English
### Download
~~~go
go get -u github.com/deatil/go-container
~~~### Get Starting
global use
~~~go
di := container.DI()
~~~customer use
~~~go
di := container.New()
~~~~~~go
package mainimport (
"fmt"
"github.com/deatil/go-container/container"
)type testBind struct {}
func (t *testBind) Data() string {
return "testBind data"
}func main() {
// Bind func
di := container.DI()
di.Bind("testBind", func() *testBind {
return &testBind{}
})
tb := di.Get("testBind")tb2, _ := tb.(*testBind)
fmt.Printf("output: %s", tb2.Data())
// output: testBind data
}func useProvide() {
// use Provide
di := container.DI()
di.Provide(func() *testBind {
return &testBind{}
})
di.Invoke(func(tb *testBind) {
fmt.Printf("output: %s", tb.Data())
// output: testBind data
})
}~~~
### LICENSE
* The library LICENSE is `Apache2`, using the library need keep the LICENSE.
### Copyright
* Copyright deatil(https://github.com/deatil).