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
Describe the bug
When a invoker need a parameter that is provided by the root container, and the provided function need a param that is provided by the child scope : the parameter needed for invoking the function will not be resolved
To Reproduce
package main
import (
"fmt""go.uber.org/dig"
)
typeconfigstruct {
strstringboolPassedInScopebool
}
funcmain() {
mainContainer:=dig.New()
mainContainer.Provide(func() string { return"Hello" })
// boolPassedInScope will be passed in the child scopemainContainer.Provide(func(helloStrstring, boolPassedInScopebool) config {
returnconfig{str: helloStr, boolPassedInScope: boolPassedInScope}
})
scope:=mainContainer.Scope("newscope")
scope.Provide(func() bool { returntrue })
// this will fail because boolPassedInScope is not provided in the main scope// and the config cannot be resolved due to the fact that in the mainContainer there// is no boolean providederr:=scope.Invoke(func(cconfig) {
fmt.Println(c.str)
fmt.Println(c.boolPassedInScope)
})
iferr!=nil {
panic(err)
}
}
Expected behavior
I don't know if it's possible but without adding dig.Export to the line scope.Provide(func() bool { return true }) the provided function to create the config should look in the child scope to find the boolPassedInScope.
Additional context
Maybe my approach is wrong but in my application framework I need to pass context, logger that is scoped because I launch multiple invoke in parallel so I can't just set them in the root container (because the logger and ctx is customized for the invoker).
Also I can't use named dig parameter because the invoker signature must not change.
The text was updated successfully, but these errors were encountered:
Hey @alexisvisco, the current design intends for child types to not be available in their parent scopes.
One possible option is to utilize a value group in the parent scope to contain all of the unique values that you were producing in your child scopes that you could call your scoped invokes with. Here the invoker signature would not change.
Describe the bug
When a invoker need a parameter that is provided by the root container, and the provided function need a param that is provided by the child scope : the parameter needed for invoking the function will not be resolved
To Reproduce
Expected behavior
I don't know if it's possible but without adding dig.Export to the line
scope.Provide(func() bool { return true })
the provided function to create theconfig
should look in the child scope to find theboolPassedInScope
.Additional context
Maybe my approach is wrong but in my application framework I need to pass context, logger that is scoped because I launch multiple invoke in parallel so I can't just set them in the root container (because the logger and ctx is customized for the invoker).
Also I can't use named dig parameter because the invoker signature must not change.
The text was updated successfully, but these errors were encountered: