-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (47 loc) · 767 Bytes
/
main.go
File metadata and controls
59 lines (47 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"github.com/pubgo/dix/v2"
"github.com/pubgo/dix/v2/dixglobal"
)
type a struct {
b
B b
}
type b struct {
C *c
}
type c struct {
C string
}
func main() {
defer func() {
if r := recover(); r != nil {
fmt.Printf("panic: %v\n", r)
}
}()
dixglobal.Provide(func() *c {
return &c{C: "hello"}
})
arg := dixglobal.Inject(new(a))
if arg.C.C != "hello" {
panic("not match")
}
fmt.Println(arg.C.C)
fmt.Println(arg.B.C.C)
dixglobal.Provide(func(a a1, di *dix.Dix, dd map[string][]*dix.Dix) *a2 {
fmt.Println(dd)
return &a2{Hello: "a2", di: di}
})
dixglobal.Inject(func(a *a2) {
fmt.Println(a.Hello)
fmt.Println(a.di.Option())
})
}
type a1 struct {
b
}
type a2 struct {
Hello string
di *dix.Dix
}