Hello,
I am using Guice 3.0 to develop an Application that consists of several
packages.
I would like to have Bindings which are only visible in one package and its
subpackages.
I have one Module per Package where I configure the Bindings used in that
package.
Currently I the Module in the root package installs the Modules in its
subpackages, which then install the Modules in their subpackages and so on.
That means if I have the following packages:
Application
Application.ComponentA
Application.ComponentB
Application.ComponentB.SubcomponentC
I would have the following Modules:
Application.ApplicationModule
Application.ComponentA.AModule
Application.ComponentB.BModule
Application.ComponentB.SubcomponentC.CModule
The ApplicationModule would look like:
public class ApplicationModule extends AbstractModule{
@Override
protected void configure() {
install(new AModule());
install(new BModule());
// Configure some Bindings
}
}
And I would create one Injector in the Main Method using:
Guice.createInjector(new MainModule());
Objects are created using Constructor and Method injection, injecting
Providers if needed.
However, if BModule maps List<String> to ArrayList<String> then AModule
also sees that Binding. Also if AModule tries to bind List<String> to
LinkedList<String> I will get a conflict.
I would like to have a binding configured in BModule to be only visible
within ComponentB and SubcomponentC. Such that a class which requests a
List<String> gets a LinkedList if its in ComponentA, a ArrayList if its in
B or C and an error if its somewhere else.
The reason is, that I would like packages on the same level to be
independent and only depend on their ancestors.
I have seen that Guice features child-injectors and PrivateModule, but I am
unsure if/how I could use that to achieve my goal.
Thanks in advance,
Martin Haug
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/d2917f17-550f-4334-b28a-883da852e14d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.