Describe the bug
First, we can:
- create an
fx.Module
- provide a type
A inside the module
- decorate the type
A inside the module
- outside the
fx.Module, populate type A
The result is that the decorate function would not have been applied.
To Reproduce
I have a testcase to reproduce this:
func TestReproPopulate(t *testing.T) {
t.Parallel()
var something string
app := fxtest.New(
t,
fx.Module("something",
fx.Provide(func() string {
return "something"
}),
fx.Decorate(func(h string) string {
return "else"
}),
),
fx.Populate(&something),
)
app.RequireStart()
app.RequireStop()
require.Equal(t, "else", something)
}
I expect that the decorate statement would have run to replace the string to else, but it stays as something. As a result, this testcase fails. I'm on the latest version of fx (v1.22.1).
However, this passes:
func TestReproPopulate(t *testing.T) {
t.Parallel()
var something string
app := fxtest.New(
t,
fx.Module("something",
fx.Provide(func() string {
return "something"
}),
),
fx.Decorate(func(h string) string {
return "else"
}),
fx.Populate(&something),
)
app.RequireStart()
app.RequireStop()
require.Equal(t, "else", something)
}
Expected behavior
I expect that the decorate inside the module still runs, and we populate the type after the decorate executes. The testcase above should pass.
Additional context
I believe this is because fx.Populate runs as an fx.Invoke, which runs at the top level scope and doesn't look at decorators in the child scope.
Describe the bug
First, we can:
fx.ModuleAinside the moduleAinside the modulefx.Module, populate typeAThe result is that the decorate function would not have been applied.
To Reproduce
I have a testcase to reproduce this:
I expect that the decorate statement would have run to replace the string to
else, but it stays assomething. As a result, this testcase fails. I'm on the latest version offx(v1.22.1).However, this passes:
Expected behavior
I expect that the decorate inside the module still runs, and we populate the type after the decorate executes. The testcase above should pass.
Additional context
I believe this is because
fx.Populateruns as anfx.Invoke, which runs at the top level scope and doesn't look at decorators in the child scope.