forked from i-love-flamingo/dingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inspect.go
66 lines (60 loc) · 2.05 KB
/
inspect.go
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
60
61
62
63
64
65
66
package dingo
import "reflect"
// Inspector defines callbacks called during injector inspection
type Inspector struct {
InspectBinding func(of reflect.Type, annotation string, to reflect.Type, provider, instance *reflect.Value, in Scope)
InspectMultiBinding func(of reflect.Type, index int, annotation string, to reflect.Type, provider, instance *reflect.Value, in Scope)
InspectMapBinding func(of reflect.Type, key string, annotation string, to reflect.Type, provider, instance *reflect.Value, in Scope)
InspectParent func(parent *Injector)
}
// Inspect the injector
func (injector *Injector) Inspect(inspector Inspector) {
if inspector.InspectBinding != nil {
for t, bindings := range injector.bindings {
for _, binding := range bindings {
var pfnc *reflect.Value
if binding.provider != nil {
pfnc = &binding.provider.fnc
}
var ival *reflect.Value
if binding.instance != nil {
ival = &binding.instance.ivalue
}
inspector.InspectBinding(t, binding.annotatedWith, binding.to, pfnc, ival, binding.scope)
}
}
}
if inspector.InspectMultiBinding != nil {
for t, bindings := range injector.multibindings {
for i, binding := range bindings {
var pfnc *reflect.Value
if binding.provider != nil {
pfnc = &binding.provider.fnc
}
var ival *reflect.Value
if binding.instance != nil {
ival = &binding.instance.ivalue
}
inspector.InspectMultiBinding(t, i, binding.annotatedWith, binding.to, pfnc, ival, binding.scope)
}
}
}
if inspector.InspectMapBinding != nil {
for t, bindings := range injector.mapbindings {
for key, binding := range bindings {
var pfnc *reflect.Value
if binding.provider != nil {
pfnc = &binding.provider.fnc
}
var ival *reflect.Value
if binding.instance != nil {
ival = &binding.instance.ivalue
}
inspector.InspectMapBinding(t, key, binding.annotatedWith, binding.to, pfnc, ival, binding.scope)
}
}
}
if inspector.InspectParent != nil && injector.parent != nil {
inspector.InspectParent(injector.parent)
}
}