di.go 866 B

12345678910111213141516171819202122232425262728293031
  1. package hero
  2. import (
  3. "reflect"
  4. "github.com/kataras/iris/hero/di"
  5. )
  6. func init() {
  7. di.DefaultHijacker = func(fieldOrFuncInput reflect.Type) (*di.BindObject, bool) {
  8. if !IsContext(fieldOrFuncInput) {
  9. return nil, false
  10. }
  11. // this is being used on both func injector and struct injector.
  12. // if the func's input argument or the struct's field is a type of Context
  13. // then we can do a fast binding using the ctxValue
  14. // which is used as slice of reflect.Value, because of the final method's `Call`.
  15. return &di.BindObject{
  16. Type: contextTyp,
  17. BindType: di.Dynamic,
  18. ReturnValue: func(ctxValue []reflect.Value) reflect.Value {
  19. return ctxValue[0]
  20. },
  21. }, true
  22. }
  23. di.DefaultTypeChecker = func(fn reflect.Type) bool {
  24. // valid if that single input arg is a typeof context.Context.
  25. return fn.NumIn() == 1 && IsContext(fn.In(0))
  26. }
  27. }