Name constructs a named instance. Name means to be used as an argument to graph.Provide. For example: Name(MyConstructor, "foo")
(constructor interface{}, name string)
| 47 | // For example: |
| 48 | // Name(MyConstructor, "foo") |
| 49 | func Name(constructor interface{}, name string) interface{} { |
| 50 | if op, ok := constructor.(OptionalProvider); ok { |
| 51 | op.Options = append(op.Options, dig.Name(name)) |
| 52 | return op |
| 53 | } |
| 54 | return OptionalProvider{ |
| 55 | Constructor: constructor, |
| 56 | Options: []dig.ProvideOption{dig.Name(name)}, |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // Bind binds a type to another. Useful when binding implementation to |
| 61 | // interfaces. The arguments should be a ptr to the binding types, rather than |
no outgoing calls