-
Notifications
You must be signed in to change notification settings - Fork 291
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
#1225
base: master
Are you sure you want to change the base?
Support multiple ResultTags
annotations
#1225
Conversation
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"`), ), ) ```
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1225 +/- ##
==========================================
- Coverage 98.42% 97.94% -0.49%
==========================================
Files 35 35
Lines 2918 2965 +47
==========================================
+ Hits 2872 2904 +32
- Misses 38 50 +12
- Partials 8 11 +3 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening up a PR for this. I added a couple of comments to start with.
defer app.RequireStart().RequireStop() | ||
}) | ||
|
||
t.Run("specify two ResultTags containing multiple tags", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a test case for using multiple As annotations and ResultTags annotations. For example, something like the following:
fx.Provide(
fx.Annotate(
func() *bytes.Buffer { return bytes.NewBuffer() },
fx.As(new(io.Reader)),
fx.As(new(io.Writer)),
fx.ResultTags(`name:"foo"`),
fx.ResultTags(`name:"bar"`),
)
)
In fact, what's the expected behavior in this case?
I think the current implementation will produce 4 results from the above code, right? But does that make sense? Does "using multiple ResultTags annotation" only make sense when there is 0 or 1 As annotation? If so, we should probably add additional logic to validate that to apply() method of resultTagsAnnotation.
) | ||
|
||
newOut.Fields = []reflect.StructField{_outAnnotationField} | ||
newOut.Offsets = []int{} | ||
// to prevent duplicate applying of the same tag to the same type, it is kept in the following format | ||
// {"foo": {"fmt.Stringer": struct{}{}, "myStringer": struct{}{}}, "bar": {"fmt.Stringer": struct{}{}}} | ||
retaggedTypeMap := map[string]map[string]struct{}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we validate whether or not a given set of ResultTags annotations will provide conflicting types to the container before we try to build out an actual constructor? (in apply() method) If we validate it beforehand, we won't have to worry about this at all here.
Closes #1210
This commit makes it possible to specify multiple
fx.ResultTags
annotations in a singlefx.Annotate
call.