go get github.com/AImager/wool
package main
import (
"fmt""github.com/AImager/wool"
)
typeAIinterface {
testA()
}
typeA1struct{}
typeA2struct{}
func (a1*A1) testA() {
fmt.Println("a1")
}
func (a2*A2) testA() {
fmt.Println("a2")
}
funcmain() {
// bind interface with factory methodaFunc:=func(namestring) AI {
switchname {
case"A1":
return&A1{}
case"A2":
return&A2{}
default:
return*new(AI)
}
}
_=wool.DI().Bind(new(AI), aFunc)
varai= (AI)(nil)
_=wool.DI().Make(&ai, "A2")
ai.testA()
// bind interface with factory// golang can't find implement struct now//_ = di.DI().Bind(new(AI), A1{})////ai1 := *new(AI)//_ = di.DI().Make(&ai1)
}PRs accepted.
MIT © AImager