-
Notifications
You must be signed in to change notification settings - Fork 8
/
instance_type.go
31 lines (24 loc) · 950 Bytes
/
instance_type.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
package goldi
import "fmt"
// instanceType is a trivial implementation of the TypeFactory interface.
// It will always `generate` the same instance of some previously instantiated type.
type instanceType struct {
// The instance that this factory is going to return on each call to Generate
Instance interface{}
}
// NewInstanceType creates a new TypeFactory which will return the given instance on each call to Generate.
// It will return an invalid type factory if the given instance is nil
//
// You can not generate this type using goldigen
func NewInstanceType(instance interface{}) TypeFactory {
if instance == nil {
return newInvalidType(fmt.Errorf("refused to create a new InstanceType with instance being nil"))
}
return &instanceType{instance}
}
func (t *instanceType) Generate(_ *ParameterResolver) (interface{}, error) {
return t.Instance, nil
}
func (t *instanceType) Arguments() []interface{} {
return []interface{}{}
}