-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathmodule_dep.go
61 lines (48 loc) · 1.44 KB
/
module_dep.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
package depinject
import (
"reflect"
"cosmossdk.io/depinject/internal/graphviz"
)
type moduleDepProvider struct {
provider *providerDescriptor
calledForModule map[*moduleKey]bool
valueMap map[*moduleKey][]reflect.Value
}
type moduleDepResolver struct {
typ reflect.Type
idxInValues int
node *moduleDepProvider
valueMap map[*moduleKey]reflect.Value
graphNode *graphviz.Node
}
func (s moduleDepResolver) getType() reflect.Type {
return s.typ
}
func (s moduleDepResolver) describeLocation() string {
return s.node.provider.Location.String()
}
func (s moduleDepResolver) resolve(ctr *container, moduleKey *moduleKey, caller Location) (reflect.Value, error) {
// Log
ctr.logf("Providing %v from %s to %s", s.typ, s.node.provider.Location, caller.Name())
// Resolve
if val, ok := s.valueMap[moduleKey]; ok {
return val, nil
}
if !s.node.calledForModule[moduleKey] {
values, err := ctr.call(s.node.provider, moduleKey)
if err != nil {
return reflect.Value{}, err
}
s.node.valueMap[moduleKey] = values
s.node.calledForModule[moduleKey] = true
}
value := s.node.valueMap[moduleKey][s.idxInValues]
s.valueMap[moduleKey] = value
return value, nil
}
func (s moduleDepResolver) addNode(p *simpleProvider, _ int) error {
return duplicateDefinitionError(s.typ, p.provider.Location, s.node.provider.Location.String())
}
func (s moduleDepResolver) typeGraphNode() *graphviz.Node {
return s.graphNode
}