-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontainer.go
42 lines (35 loc) · 941 Bytes
/
container.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
package axon
import (
"reflect"
)
type container[T any] interface {
GetValue() T
GetReflectValue() reflect.Value
// GetExternalDependencies returns Keys that may be required that aren't explicitly listed on the container's value e.g. dependencies grabbed in a Factory.
GetExternalDependencies() []Key
}
func newContainer[T any](v T, externalDeps ...Key) container[T] {
return &containerImpl[T]{
Value: v,
ExternalDependencies: externalDeps,
}
}
type containerImpl[T any] struct {
Value T
ReflectValue *reflect.Value
ExternalDependencies []Key
}
func (c *containerImpl[T]) GetExternalDependencies() []Key {
return c.ExternalDependencies
}
func (c *containerImpl[T]) GetValue() T {
return c.Value
}
func (c *containerImpl[T]) GetReflectValue() reflect.Value {
if c.ReflectValue == nil {
v := reflect.ValueOf(c.Value)
c.ReflectValue = &v
return v
}
return *c.ReflectValue
}