Skip to content

Sorting within a group of dependencies #886

Answered by abhinav
talgendler asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, @talgendler, thanks for the proposal.
Sorry, we don't think Dig/Fx should support weight-based value groups.
However, there's a pattern we can recommend instead.
Read on for details.

Background:
Value groups are intended to be used for unordered collections only.
We specifically made that decision when designing the API,
and we intentionally randomize the order in which the value group is filled:
https://github.com/uber-go/dig/blob/173b7b1935ec5ea6b26ebaf0b513658752f58c79/dig.go#L479

We felt that for cases when ordering mattered, it really mattered.
For those cases, it was desirable for the application to have full control on the order.
An API based on weights/z-indexing allows any…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by abhinav
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #807 on May 27, 2022 23:49.