Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: easy constructor wrapper for named/grouped values #715

Closed
oakad opened this issue Oct 5, 2020 · 1 comment
Closed

Feature request: easy constructor wrapper for named/grouped values #715

oakad opened this issue Oct 5, 2020 · 1 comment

Comments

@oakad
Copy link

oakad commented Oct 5, 2020

fx.Annotated makes it easy to produce named and grouped values. But on the consumer side things are less pretty.

Let's say we have a constructor with many parameters and we want to make some of them named/grouped. Right now, the only option to address this is by creating a wrapper function taking an fx.In derived parameter resulting in a rather long winded and untidy boilerplate code with some one off struct types on top.

It may be possible to come with a constructor wrapper accepting a hint of some sort in addition to the constructor; possibly as simple as a specially coded string:

fx.New(
  fx.Provide(
    fx.WithNames(", , funnyName,", myCons),
  ),
)

The implied meaning being that third argument of myCons must come from a provider annotated with name "funnyName"

.

@abhinav
Copy link
Collaborator

abhinav commented Nov 4, 2021

Hey there! This was added in #757. You should be able to do:

fx.Provide(
  fx.Annotate(myCons, fx.ParamTags("", "", `name:"funnyName"`)),
)

We haven't released it yet—we're hoping to do that right after we finish work on #795.
Stay tuned!

Closing the ticket pending release of the feature.

@abhinav abhinav closed this as completed Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants