dig.As
How do I use dig.As with an fx app?
dig.As hasn't been released yet, you can see https://github.com/uber-go/dig/pull/235 for why it was halted slightly.
The plan for usage inside fx is through fx.Annotated (not implemented yet) that will function similarly to how fx.Annotated can do named and grouped params.
Going to leave this issue open to track the fx.Annotated.As work.
Hi @glibsm I am having the same problem as you, the issues have been resolved yet ?
fx.As has been implemented with #795.
I was testing this solution with the provided example in the docs, but I am getting error type io.Writer is not an expression . Am I missing something?
fx.Provide(
fx.Annotate(bytes.NewBuffer([]byte{}), fx.As(io.Writer)),
)
@AFMiziara you're missing a new. Interface itself is not a valid expression in Go.
fx.Provide(
fx.Annotate(bytes.NewBuffer([]byte{}), fx.As(new(io.Writer)))
)
I see that in the docs we forgot to add the new there. Let me go fix that.
Oh! Totally my bad. I didn't even realized that :) Thanks for the fast reply @sywhang !