golang 依赖注入应用

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]&#

你可能感兴趣的:(golang,依赖注入)