-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (36 loc) · 736 Bytes
/
main.go
File metadata and controls
44 lines (36 loc) · 736 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
package main
import (
"fmt"
"github.com/pubgo/dix/v2/dixglobal"
)
func main() {
defer func() {
if r := recover(); r != nil {
fmt.Printf("panic: %v\n", r)
}
}()
type handler func() string
dixglobal.Provide(func() handler {
return func() string {
return "hello"
}
})
dixglobal.Provide(func() handler {
return func() string {
return "world"
}
})
type param struct {
H handler
List []handler
}
fmt.Println("struct: ", dixglobal.Inject(new(param)).H())
dixglobal.Inject(func(h handler, list []handler) {
fmt.Println("inject: ", h())
fmt.Println("inject: ", list)
})
dixglobal.Inject(func(p param) {
fmt.Println("inject struct: ", p.H())
fmt.Println("inject struct: ", p.List)
})
}