Skip to content

Ability to combine multiple containers #229

Description

@maciej

Hi,

I'd like to be able to combine multiple containers together. Instead of having a single container assembled within the main function I'd like to have one for each package and them combine them in main().
Currently I have to export every constructor or provider function to have it accessible from where I want to build the container. That's not great. I'd like some of those constructors to be package-private.
I believe there is currently no way to achieve that in dig, but please correct me if I'm wrong!

I'm inspired by Guice's modules https://github.com/google/guice/wiki/GettingStarted. Guice's users were encouraged to have a single "module" (a similar construct to the container) for every package. Modules would we later assembled when creating the "injector".

Do you think such a feature would make sense for dig?

Activity

  1. abhinav commented on Dec 12, 2018

    @abhinav
    Collaborator

    Hello! We agree that that is a great idea which is why we built Fx on top
    of Dig to make that possible!

    We intended Dig to be the lower level library on top of which we could build a
    more opinionated framework. Dig handles the dependency resolution,
    instantiation, etc. with a few primitives (the container, dig.In/Out, etc.).
    Fx builds on top of that with opinions on how you should structure your
    application, and enables composition of modules produced by different packages.

    Please check out Fx and see if it fits your needs. We recommend the
    heavily commented package-level example test on https://godoc.org/go.uber.org/fx
    as a starting point.

  2. locked and limited conversation to collaborators on Sep 20, 2022
  3. converted this issue into a discussion #358 on Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions