fx icon indicating copy to clipboard operation
fx copied to clipboard

dig.As

Open rssathe opened this issue 7 years ago • 7 comments

How do I use dig.As with an fx app?

rssathe avatar Apr 19 '19 03:04 rssathe

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.

glibsm avatar Apr 19 '19 21:04 glibsm

Going to leave this issue open to track the fx.Annotated.As work.

glibsm avatar Apr 19 '19 21:04 glibsm

Hi @glibsm I am having the same problem as you, the issues have been resolved yet ?

phamtai97 avatar Sep 07 '20 15:09 phamtai97

fx.As has been implemented with #795.

sywhang avatar Nov 04 '21 22:11 sywhang

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 avatar Nov 09 '21 22:11 AFMiziara

@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.

sywhang avatar Nov 09 '21 22:11 sywhang

Oh! Totally my bad. I didn't even realized that :) Thanks for the fast reply @sywhang !

AFMiziara avatar Nov 09 '21 22:11 AFMiziara