-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_build.go
38 lines (32 loc) · 920 Bytes
/
container_build.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
package autowire
import (
"context"
"reflect"
)
// Build implementation of Container interface
func (c *container) Build(targetType reflect.Type, opts ...ContextOption) (value reflect.Value, err error) {
provider, err := c.providerSet.GetFor(targetType)
if err != nil {
return value, err
}
ctx := &Context{
sharedMode: c.sharedMode,
providerSet: c.providerSet.shallowClone(),
objectMap: c.objectMap,
resolvingTypes: make(map[reflect.Type]struct{}, 10), //nolint:gomnd
}
for _, opt := range opts {
opt(ctx)
}
value, err = provider.Build(ctx, targetType)
if err != nil {
return value, err
}
return value, nil
}
// BuildWithCtx implementation of Container interface
func (c *container) BuildWithCtx(ctx context.Context, targetType reflect.Type, opts ...ContextOption) (
value reflect.Value, err error,
) {
return c.Build(targetType, append(opts, ProviderOverwrite(ctx))...)
}