-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support fx.Private w/ fx.Supply (#1207)
`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 #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.
- Loading branch information
Showing
3 changed files
with
222 additions
and
118 deletions.
There are no files selected for viewing
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
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
Oops, something went wrong.