mirror of
https://github.com/kataras/iris.git
synced 2026-01-24 20:35:59 +00:00
create a new package, name it as hero, I was thinking super or superb but hero is better name for what it does - the goal is to split the new 'mvc handlers' from the mvc system because they are not the same, users should know that they can use these type of rich binded handlers without controllers as well, like a normal handler and that I implemented here, the old files exist on the mvc package but will be removed at the next commit, I have to decide if we want type aliases for Result or no
Former-commit-id: cb775edc72bedc88aeab4c5a6de6bfc6bd56fae2
This commit is contained in:
31
hero/di.go
Normal file
31
hero/di.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package hero
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/kataras/iris/hero/di"
|
||||
)
|
||||
|
||||
func init() {
|
||||
di.DefaultHijacker = func(fieldOrFuncInput reflect.Type) (*di.BindObject, bool) {
|
||||
if !IsContext(fieldOrFuncInput) {
|
||||
return nil, false
|
||||
}
|
||||
// this is being used on both func injector and struct injector.
|
||||
// if the func's input argument or the struct's field is a type of Context
|
||||
// then we can do a fast binding using the ctxValue
|
||||
// which is used as slice of reflect.Value, because of the final method's `Call`.
|
||||
return &di.BindObject{
|
||||
Type: contextTyp,
|
||||
BindType: di.Dynamic,
|
||||
ReturnValue: func(ctxValue []reflect.Value) reflect.Value {
|
||||
return ctxValue[0]
|
||||
},
|
||||
}, true
|
||||
}
|
||||
|
||||
di.DefaultTypeChecker = func(fn reflect.Type) bool {
|
||||
// valid if that single input arg is a typeof context.Context.
|
||||
return fn.NumIn() == 1 && IsContext(fn.In(0))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user