google / google/guice

Documentation - Confusion with PrivateModule behavior

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

Description

Hello Guice,

Documentation of PrivateModule say that:
> A module whose configuration information is hidden from its environment by default. Only bindings that are explicitly exposed will be available to other modules and to the users of the injector. This module may expose the bindings it creates and the bindings of the modules it installs

However I'm not sure what is `hidden configuration information`

As far as I know, the behavior of PrivateModule is that:
* if a binding is not exposed, then you can not declare it(1)

(1) let to this confuse situation that you can not using `combine`/`override` with following modules:
* a PrivateModule `P` which has non-exposed binding of class `C`

```java
public class P extends PrivateModule {
void configure() {
bind(C.class).toInstance(new C("Private C"));
}
}
```

* a normal Module `N` which has also binding of class `C`

```java
public class N extends AbstractModule {
void configure() {
bind(C.class).toInstance(new C("Any C"));
}
}
```

The error is `A binding to ... was already configured ....`, which recognize `configuration environment`!

So do you think that PrivateModule documentation should be updated? And if it is possible, an example which describe why PrivateModule exists would be great.

Thank you in advance.

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.