https://github.com/browny/inject
Golang injection framework based on https://github.com/facebookgo/inject
https://github.com/browny/inject
constructor dependency-injection golang injection-framework
Last synced: about 1 month ago
JSON representation
Golang injection framework based on https://github.com/facebookgo/inject
- Host: GitHub
- URL: https://github.com/browny/inject
- Owner: browny
- License: bsd-3-clause
- Created: 2017-07-31T15:33:00.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-31T16:05:56.000Z (over 8 years ago)
- Last Synced: 2024-06-20T14:29:25.159Z (almost 2 years ago)
- Topics: constructor, dependency-injection, golang, injection-framework
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# inject [](http://godoc.org/github.com/browny/inject)
Golang injection framework based on https://github.com/facebookgo/inject
## Usage
See how it works in `inject_test.go` by running `go test`
```go
func (s *InjectTestSuite) TestWeave() {
driver := example.Driver{}
farmer := example.Farmer{}
master := example.Master{}
myLogger := example.MyLogger{}
tillageMachine := example.TillageMachine{}
depMap := map[interface{}][]string{
&myLogger: []string{
"logger",
},
&driver: []string{
"example.Master.Transport",
},
&farmer: []string{
"example.Master.Food",
},
&tillageMachine: []string{
"example.TillageMachine.Machine",
},
&master: []string{},
}
graph, err := Weave(depMap)
s.NoError(err)
master.Food.GetRice()
master.Transport.Fly("C++", "Go")
f := graph[reflect.TypeOf(&example.Farmer{})].(*example.Farmer)
f.Machine.Run(5)
}
```