package main
import (
"fmt"
"github.com/facebookgo/inject"
"os"
)
type Client interface{
TestServer()
}
type Test struct {
Name string
Address string
}
type Two struct {
Email string
Number string
}
type X struct {
Info *Test `inject:""`
Res *Two `inject:""`
Factory Client `inject:""`
}
type FactoryTest struct{}
func (ft *FactoryTest) TestServer() {
fmt.Println("factory test")
}
type TestFactory struct{}
func (ft *TestFactory) TestServer() {
fmt.Println("test factory")
}
func (x *X) PrintX() {
fmt.Println("name is", x.Info.Name)
fmt.Println("email is", x.Res.Email)
}
func main() {
var g inject.Graph
var x X
valx := Test{Name: "test-x", Address: "SZ"}
valy := Two{Email: "[email protected]", Number: "1231242423"}
//factory := FactoryTest{}
tf := TestFactory{}
err := g.Provide(&inject.Object{Value:&va
golang 依賴注入應用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.