MCPcopy Index your code
hub / github.com/DoNewsCode/core / Bind

Function Bind

di/optional_provider.go:64–72  ·  view source on GitHub ↗

Bind binds a type to another. Useful when binding implementation to interfaces. The arguments should be a ptr to the binding types, rather than the types themselves. For example: Bind(new(MyConcreteStruct), new(MyAbstractInterface))

(from interface{}, to interface{})

Source from the content-addressed store, hash-verified

62// the types themselves. For example:
63// Bind(new(MyConcreteStruct), new(MyAbstractInterface))
64func Bind(from interface{}, to interface{}) interface{} {
65 fromTypes := []reflect.Type{reflect.TypeOf(from).Elem()}
66 toTypes := []reflect.Type{reflect.TypeOf(to).Elem()}
67 fnType := reflect.FuncOf(fromTypes, toTypes, false /* variadic */)
68 fn := reflect.MakeFunc(fnType, func(args []reflect.Value) []reflect.Value {
69 return args
70 })
71 return fn.Interface()
72}

Callers 10

ProvidersFunction · 0.92
TestBindFunction · 0.92
ProvidersFunction · 0.92
ProvidersFunction · 0.92
ProvidersFunction · 0.92
ProvidersFunction · 0.92
ProvidersFunction · 0.92
ProvidersFunction · 0.92

Calls

no outgoing calls

Tested by 3

TestBindFunction · 0.74