kataras/iris · error
binder: DisableStructDynamicBindings setting is set to true:
Error message
binder: DisableStructDynamicBindings setting is set to true: dynamic binding found: %s
What it means
When Container.DisableStructDynamicBindings is true, every field binding of a registered struct must be static (resolved once at setup). A field whose dependency is dynamic (resolved per request) is rejected with this panic, keeping the struct a singleton.
Source
Thrown at hero/struct.go:101
// fmt.Printf("Service: %s, Bindings(%d):\n", typ, len(bindings))
for _, b := range bindings {
// fmt.Printf("* " + b.String() + "\n")
if b.Dependency.Static {
// Fill now.
input, err := b.Dependency.Handle(nil, b.Input)
if err != nil {
if err == ErrSeeOther {
continue
}
panic(err)
}
elem.FieldByIndex(b.Input.StructFieldIndex).Set(input)
} else if !b.Dependency.Static {
if disableStructDynamicBindings {
panic(fmt.Sprintf("binder: DisableStructDynamicBindings setting is set to true: dynamic binding found: %s", b.String()))
}
singleton = false
}
}
if isSingleton && !singleton {
panic(fmt.Sprintf("binder: Singleton setting is set to true but struct has dynamic bindings: %s", typ))
}
s := &Struct{
ptrValue: v,
ptrType: typ,
elementType: elem.Type(),
bindings: bindings,
Singleton: singleton,
}
View on GitHub (pinned to 7bedaf55a0)
Solutions
- Remove or change the dynamic field to a static dependency type (a service/config registered at startup).
- Set c.DisableStructDynamicBindings = false if dynamic per-request fields are intended (struct stops being a singleton).
- Split the struct: keep static fields in the singleton struct and move request-scoped data into handler parameters.
- Inspect b.Dependency.Static for each field binding to identify which one is dynamic.
Example fix
// before
c.DisableStructDynamicBindings = true
c.Struct(&Controller{ /* has field Payload *UserRequest -> dynamic */ })
// after
c.Struct(&Controller{ Svc *UserService }) // only static fields
// and handle request payloads via handler method parameters instead Defensive patterns
Strategy: validation
Validate before calling
// Before enabling DisableStructDynamicBindings, audit struct fields:
for each field binding b of target struct {
if !b.Dependency.Static { panic("dynamic field: " + b.String()) }
}
c.DisableStructDynamicBindings = true Prevention
- Only enable DisableStructDynamicBindings when all controller fields are static services/config.
- Keep request-scoped inputs in handler method parameters, not struct fields.
- Split mixed structs into a static singleton plus per-request handler inputs.
When it happens
Trigger: Registering a struct with c.Struct where one field's type resolves to a per-request dependency (e.g. request payload, path parameter) while DisableStructDynamicBindings = true.
Common situations: Enabling the optimization setting globally but one controller struct still has a dynamic field (e.g. a request body input); adding a new request-scoped field to an existing singleton controller after enabling the setting.
Related errors
- binder: Singleton setting is set to true but struct has dyna
- api container: set dependency matcher: fn cannot be nil
- bindings: unresolved: no a func type: %#+v
- expected [%d] bindings (input parameters) but got [%d] Funct
- bindings: unresolved: not a struct type: %#+v
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/da80b967ab2e6fb8.
Report an issue: GitHub.