Skip to content

Support composing multibinders for private modules #1272

@cconroy

Description

@cconroy

When creating a multibinder with the same key as the parent module in a PrivateModule, guice produces an error. This check avoids the confusing situation of having different multibindings based on the location of injection, but it creates a problem: if a private module wants to "inherit" all of the multi-bindings from the parent in its own multibinder with a different key, it must manually re-state each binding. This is error-prone and cumbersome.

To support this use case, we could allow a multibinder to copy/inherit all the bindings from another multibinder of the same type. e.g. LinkedBindingBuilder<T> inheritBindings(Multibinder<T> multibinder)

Motivation: Multibinders are often used with AOP type patterns. I recently found a case in our code base where private datasource modules were not getting important execution listeners wired up to terminate long running database queries!

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