-
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 fx.Private w/ fx.Supply #1207
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`fx.Supply` is essentially an API that allows for conveniently `fx.Provide`ing an exact value, rather than a function that will return that value. For example, `fx.Provide(func() int { return 5 })` is equivalent to `fx.Supply(5)`. `fx.Private` allows for usage of a provided constructor's results to be restricted to the current module and its child modules. ```go fx.Module( "parent", fx.Invoke(func(int) { /* this will error out! */ }), fx.Module( "child", fx.Provide(func() int { return 5 }, fx.Private), ), ), ``` This PR allows for using `fx.Private` with `fx.Supply` as well, so that folks can enjoy the convenience of `fx.Supply` when they also wish to restrict the usage of the supplied value. ```go fx.Module( "parent" fx.Invoke(func(int) { /* this will error out! */ }), fx.Module( "child", fx.Supply(5, fx.Private), ), ), ``` Ref uber-go#1206 Since the behavior between Supply + Private and Provide + Private should be identical, I opted to generalize the existing `fx.Private` tests to run for both Provide and Supply. This keeps the tests a little more DRY but does complicate them/hurt readability. I feel like this is OK since there are a lot of tests, but I also am the one who wrote the tests, so I am biased regarding its readability. I am happy to break out Supply + Private into its own tests if folks think these tests are getting cluttered.
JacobOaks
force-pushed
the
joaks/private_supply
branch
from
May 29, 2024 17:33
b558e53
to
258fe12
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1207 +/- ##
==========================================
- Coverage 98.51% 98.41% -0.10%
==========================================
Files 34 34
Lines 2900 2908 +8
==========================================
+ Hits 2857 2862 +5
- Misses 36 38 +2
- Partials 7 8 +1 ☔ View full report in Codecov by Sentry. |
JacobOaks
added a commit
to JacobOaks/fx
that referenced
this pull request
May 29, 2024
This updates the changelog and the version for a 1.22.0 release. I will wait to merge this until uber-go#1207 is reviewed. Ref: uber-go#1204
Merged
sywhang
approved these changes
May 30, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fx.Supply
is essentially an API that allows for convenientlyfx.Provide
ing an exact value, rather than a function that will return that value. For example,fx.Provide(func() int { return 5 })
is equivalent tofx.Supply(5)
.fx.Private
allows for usage of a provided constructor's results to be restricted to the current module and its child modules.This PR allows for using
fx.Private
withfx.Supply
as well, so that folks can enjoy the convenience offx.Supply
when they also wish to restrict the usage of the supplied value.Ref #1206
Since the behavior between Supply + Private and Provide + Private should be identical, I opted to generalize the existing
fx.Private
tests to run for both Provide and Supply. This keeps the tests a little more DRY but does complicate them/hurt readability. I feel like this is OK since there are a lot of tests, but I also am the one who wrote the tests, so I am biased regarding its readability. Thus, I am happy to break out Supply + Private into its own tests if folks feel strongly that these tests are hard to read.