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

Support multiple ResultTags annotations #1210

Open
jmmills opened this issue May 30, 2024 · 0 comments · May be fixed by #1225
Open

Support multiple ResultTags annotations #1210

jmmills opened this issue May 30, 2024 · 0 comments · May be fixed by #1225

Comments

@jmmills
Copy link

jmmills commented May 30, 2024

As multiple  As annotations are supported, it would make sense to support multiple ResultTag annotations.

Currently this code fails with cannot apply more than one line of ResultTags

func main() {
	app := fx.New(
		fx.Provide(
			fx.Annotate(
				func() *bytes.Buffer {
					return bytes.NewBuffer([]byte("Hello!"))
				},
				fx.ResultTags(`name:"a"`),
				fx.ResultTags(`name:"b"`),
			),
		),
		fx.Invoke(
			fx.Annotate(
				func(a, b *bytes.Buffer) {
					fmt.Println(a.String())
					fmt.Println(b.String())
				},
				fx.ParamTags(
					`name:"a"`,
					`name:"b"`,
				),
			),
		),
	)
	app.Run()
}

A work-around is possible by providing multiple copies of the same instance of a type, however it is less intuitive.

fx.Provide(
    fx.Annotate(
        func() (*bytes.Buffer, *bytes.Buffer) {
            a := bytes.NewBuffer([]byte("Hello!"))
            b := a
            return a, b
        },
        fx.ResultTags(`name:"a"`, `name:"b"`),
    ),
)

Is this a breaking change?
It should not be a breaking change as nothing (sans tests) should rely on app failure for multiple result tag annotations.

miyamo2 added a commit to miyamo2/fx that referenced this issue Jul 10, 2024
Closes uber-go#1210

This commit makes it possible to specify multiple `fx.ResultTags` annotations in a single `fx.Annotate` call.

```go
fx.Provide(
    fx.Annotate(
        func() *bytes.Buffer {
            return bytes.NewBuffer([]byte("Hello!"))
        },
        fx.ResultTags(`name:"a"`),
        fx.ResultTags(`name:"b"`),
        fx.ResultTags(`name:"c"`),
    ),
)
```
@miyamo2 miyamo2 linked a pull request Jul 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants