Skip to content

Latest commit

 

History

History
40 lines (34 loc) · 946 Bytes

README.md

File metadata and controls

40 lines (34 loc) · 946 Bytes

inject GoDoc

Golang injection framework based on https://github.com/facebookgo/inject

Usage

See how it works in inject_test.go by running go test

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)
}