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: "reneandy@126.com&#
golang 依赖注入应用
最新推荐文章于 2023-06-02 09:41:29 发布