Bind: takes a pointer for the second argument (#152)

This commit is contained in:
shantuo
2019-04-12 23:50:45 -07:00
committed by GitHub
parent 65ae46b7ea
commit e9e631cd71
20 changed files with 147 additions and 33 deletions

12
wire.go
View File

@@ -93,9 +93,9 @@ func Build(...interface{}) string {
// A Binding maps an interface to a concrete type.
type Binding struct{}
// Bind declares that a concrete type should be used to satisfy a
// dependency on the type of iface, which must be a pointer to an
// interface type.
// Bind declares that a concrete type should be used to satisfy a dependency on
// the type of iface. iface must be a pointer to an interface type, to must be a
// pointer to a concrete type.
//
// Example:
//
@@ -108,12 +108,16 @@ type Binding struct{}
// func (MyFoo) Foo() {}
//
// var MySet = wire.NewSet(
// MyFoo{},
// wire.Struct(new(MyFoo))
// wire.Bind(new(Fooer), new(MyFoo)))
func Bind(iface, to interface{}) Binding {
return Binding{}
}
// bindToUsePointer is detected by the wire tool to indicate that Bind's second argument should take a pointer.
// See https://github.com/google/wire/issues/120 for details.
const bindToUsePointer = true
// A ProvidedValue is an expression that is copied to the generated injector.
type ProvidedValue struct{}