google / google/guice

Support composing multibinders for private modules

Open
#1,272 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

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 inheritBindings(Multibinder 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!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.