uber-go / dig

A reflection based dependency injection toolkit for Go.
https://go.uber.org/dig
MIT License
3.78k stars 206 forks source link

Allow name and group Result Tags #380

Open jquirke opened 1 year ago

jquirke commented 1 year ago

Describe the solution you'd like

This is linked from an Fx feature request: https://github.com/uber-go/fx/issues/998

Furthermore, it is a necessary stepping stone to another Fx feature request https://github.com/uber-go/fx/issues/1036

The restriction on allowing name and group tags seems artificial. For example, this is not permitted:

type Result struct {
    dig.Out
    Foo1 Foo `name:"foo1" group:"foos"`
}

In order to populate by name and groups elsewhere.

Describe alternatives you've considered

An output dig struct can be written with multiple outputs, but that is rather clumsy.

type Result struct {
    dig.Out
    Foo1 Foo `name:"foo1"`
    Foos []Foo `group:"foos"`
}

Is this a breaking change?

Not likely. Since the desired behaviour is not currently permitted, it should not break any existing applications.