You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To Reproduce
The following code will be reproduce this bug
package main
import (
"github.com/kataras/iris/v12""github.com/kataras/iris/v12/mvc""log"
)
typeServicestruct{}
func (s*Service) DoSomething(ctx iris.Context) {
if_, err:=ctx.WriteString("Foo bar"); err!=nil {
log.Println(err)
}
}
typeControllerstruct {
Ctx iris.ContextService*Service
}
typeFooControllerstruct {
Controller
}
typeBarControllerstruct {
FooController
}
typeFinalControllerstruct {
BarController
}
func (c*FinalController) Get() {
// c.Ctx and c.Service are not injected// this action will trigger a panicc.Service.DoSomething(c.Ctx)
}
funcmain() {
app:=iris.New()
m:=mvc.New(app)
m.Register(new(Service))
m.Handle(new(FinalController))
iferr:=app.Listen(":8080"); err!=nil {
log.Fatal(err)
}
}
Desktop:
OS: ubuntu 18.04
After debugging I found a possible cause of this bug struct.go reflect.go
In my gist case, the field.Index of all fields returned by LookupNonZeroFieldsValues will be come the last field.Index value
Then I try to fix this bug, I added the following code in reflect.go
Hello @rocinantex, the dependency injection code is fully re-written in the upcoming version of Iris, see the master branch. Try it, (see the new examples as well), and if your code still failing please post the code snippet in order to provide you more help, don't try to fix it alone, just share a re-producible code.
Dependencies injection failed
To Reproduce
The following code will be reproduce this bug
Desktop:
After debugging I found a possible cause of this bug
struct.go
reflect.go
In my gist case, the
field.Index
of all fields returned byLookupNonZeroFieldsValues
will be come the lastfield.Index
valueThen I try to fix this bug, I added the following code in
reflect.go
Then the bug disappeared, but I still don't know why.
Because
index
is a local variable, why does it cause all fields to be modified?The text was updated successfully, but these errors were encountered: