uber-go/dig

Be able to define provider sets?

nolotz opened this issue · 1 comments

Hi there,

I'm started using your framework and coming from golang wire.

Is there a possibility to group dependencies into sets and
reuse them throughout containers & modules, including ProvideOptions?

// module a
var (
	WireSet = wire.NewSet(
		NewBackend,
		wire.Bind(new(Backend), new(*lambdasdk.Client)),
	)
)

// module b
func ProvideService(ctx context.Context) (*Service, error) {
	wire.Build(
		moduleA.WireSet,
		NewService,
	)
	return &Service{}, nil
}

I really appreciate any help you can provide.

Best regards,
Noah

Hi @nolotz,

For your use case, we recommend checking out fx, a DI-based framework built on top of Dig: https://uber-go.github.io/fx/

The provide options available in Dig are also available (with the exception of private provide, which is planning to be added soon). fx.Module is the exact thing you're looking for (grouping providers into sets and reusing them between modules). Most of Uber's internal libraries are built on top of fx to make them reusable across the services.

HTH,
Sung