oghenez / mycila

Automatically exported from code.google.com/p/mycila
0 stars 0 forks source link

Jsr250Injector calls modules initialization method twice and instantiates singletons twice #42

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I might be completely off here, but it seems to me that when I use 
Jsr250Injector.createInjector() the modules configure() methods are called 
twice.

Also, if I bind singleton like this:

{{{
   bind(Foo.class).toInstance(new Foo());
}}}

then the two instances of Foo are created. If bean is annotated with @Signleton 
it works as expected.

When the same code is run with plain Guice.createInjector it works as expected.

I attached a JUnit test that tests these issues with plain 
Guice.createInjector() and with Jsr250Injector.createInjector().

Br, Jarppe Lansio

Original issue reported on code.google.com by jar...@gmail.com on 12 Mar 2012 at 3:48

Attachments:

GoogleCodeExporter commented 8 years ago
Hi,

This is the way guice works. When it introspects module, it loads them each 
time you call Elements.getElements().

Developpers have to be careful about this so that configure() method in modules 
can be called several times to setup bindings without impacting the application 
states.

Original comment by mathieu....@gmail.com on 22 Mar 2012 at 6:24

GoogleCodeExporter commented 8 years ago

Original comment by mathieu....@gmail.com on 22 Mar 2012 at 6:24