github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zdi/lazy.go (about)

     1  package zdi
     2  
     3  import (
     4  	"reflect"
     5  
     6  	"github.com/sohaha/zlsgo/zreflect"
     7  )
     8  
     9  func (inj *injector) Provide(provider interface{}, opt ...Option) (override []reflect.Type) {
    10  	val := zreflect.ValueOf(provider)
    11  	t := val.Type()
    12  	numout := t.NumOut()
    13  	for i := 0; i < numout; i++ {
    14  		out := t.Out(i)
    15  		if _, ok := inj.values[out]; ok {
    16  			override = append(override, out)
    17  		}
    18  		if _, ok := inj.providers[out]; ok {
    19  			override = append(override, out)
    20  		}
    21  		inj.providers[out] = val
    22  	}
    23  	return
    24  }