Re: Comment on GuiceCompatibility in google-gin

72 views
Skip to first unread message

googl...@googlecode.com

unread,
Feb 7, 2010, 6:02:09 AM2/7/10
to googl...@googlegroups.com
Comment by yadoo86:

Sorry Guys... I don't get it... how singleton scope is supported it? Every
time, user refreshes page, a new module is created. Right?


For more information:
http://code.google.com/p/google-gin/wiki/GuiceCompatibility

jocke eriksson

unread,
Feb 7, 2010, 6:11:56 AM2/7/10
to googl...@googlegroups.com
This is the same if you have a Main method. Every java -jar my.jar is executed a new set of singletons are created.  


--
You received this message because you are subscribed to the Google Groups "google-gin" group.
To post to this group, send email to googl...@googlegroups.com.
To unsubscribe from this group, send email to google-gin+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-gin?hl=en.


jocke eriksson

unread,
Feb 7, 2010, 6:16:18 AM2/7/10
to googl...@googlegroups.com
Sorry spoke to soon! I hope that singeltons are created in the global context this way there will only be one instance.

2010/2/7 jocke eriksson <joc...@gmail.com>

Jeff Chimene

unread,
Feb 7, 2010, 10:49:27 AM2/7/10
to googl...@googlegroups.com
You could always compile using style detailed and review the generated code...

googl...@googlecode.com

unread,
Feb 14, 2010, 5:19:41 PM2/14/10
to googl...@googlegroups.com
Comment by spirydonau:

have same question as yadoo86
it does not even need a page refresh. I need an instance of HandlerManager
as event bus throughout the app. since it doesn't have a default
constructor I declared following in my module
{{{
private final HandlerManager eventBus = new HandlerManager(null);
}}}
and added method
{{{
@Provides HandlerManager getEventBus() { return eventBus; }
}}}
to my bitter disappointment I have a new instance of the bus every time it
is injected somewhere. suggestions are very welcome.

Jeff Larsen

unread,
Feb 14, 2010, 5:26:18 PM2/14/10
to googl...@googlegroups.com
Since you want that to be a singleton, what is the reason for doing that via a provider? Some options would be to create a new interface EventBus which is then implemented by a new class that you create which extends HandlerManager and implements EventBus (lets call it GlobalEventBus)

class GlobalEventBus extends HandlerManager implements EventBus{


    public GlobalEventBus(){
        super(null);
     }
}

then in your moduel you bind it such as 

bind(EventBus.class).to(GlobalEventBus.class).in(Singleton.class);

Please forgive any typos. I haven't had a chance to work with gin/guice for a while. 

Now you would just inject the EventBus into everywhere you want instead of mapping a Provider to it. Now if you preferred a provider method, you can still do that with this implementation. Just inject Provider<EventBus> and you'll have access to the provoder portion of that method. 


Peter Schmitt

unread,
Feb 18, 2010, 8:26:34 AM2/18/10
to googl...@googlegroups.com
If you want to use a singleton with a custom initialization (executed in a provider method), do the following:

public class MyModule extends AbstractGinModule {

  public void configure() {}

  @Provides
  @Singleton
  HandlerManager provideHandlerManager() {
    return new HandlerManager(null);
  }
}

This way, Gin will make sure that the provider method is only called once.

Hope this helps!

Peter

googl...@googlecode.com

unread,
Mar 6, 2010, 4:11:34 PM3/6/10
to googl...@googlegroups.com
Comment by fabiokaminski:

i would like to see toInstance() implemented too.. :(
besides that.. congrats for this big tool!

googl...@googlecode.com

unread,
Mar 6, 2010, 6:11:02 PM3/6/10
to googl...@googlegroups.com
Comment by fabiokaminski:

just a thought.. are you planing to implement some way to inject UIBinder
into the ui instead of what we are doing right now.. that is create the
uibinder interface each time for each widget trough the GWT.create()??

some way to inject that?

Thanks

googl...@googlecode.com

unread,
Mar 8, 2010, 3:49:41 PM3/8/10
to googl...@googlegroups.com
Comment by aragos:

Note that you can easily replace toInstance bindings with an analogous
provider method, i.e:

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

becomes:

{{{
@Provides
@Singleton
Foo provideFoo() {
return new Foo();

googl...@googlecode.com

unread,
Jun 2, 2010, 12:19:27 PM6/2/10
to googl...@googlegroups.com
Comment by debillin:

Assisted Inject is missing

googl...@googlecode.com

unread,
Mar 18, 2011, 1:08:24 PM3/18/11
to googl...@googlegroups.com
Comment by sne...@gmail.com:

I'm assuming Custom Injections are not supported in Gin?
http://code.google.com/p/google-guice/wiki/CustomInjections

googl...@googlecode.com

unread,
Mar 27, 2011, 7:53:26 AM3/27/11
to googl...@googlegroups.com
Comment by andy.stevko:

A note on Guice Compatibility -
map class FactoryModuleBuilder to GinFactoryModuleBuilder

googl...@googlecode.com

unread,
May 9, 2011, 5:00:49 AM5/9/11
to googl...@googlegroups.com
Comment by jamie.cr...@gmail.com:

Is this representative of what's currently in GIN 1.5?

googl...@googlecode.com

unread,
May 19, 2011, 8:01:41 PM5/19/11
to googl...@googlegroups.com
Comment by laze...@google.com:

How about ThrowingProvider? CheckedProvider?

googl...@googlecode.com

unread,
May 24, 2013, 4:50:08 PM5/24/13
to googl...@googlegroups.com
Comment by baronce...@google.com:

Table needs to be updated, now that multibinding is available.

For more information:
https://code.google.com/p/google-gin/wiki/GuiceCompatibility

googl...@googlecode.com

unread,
Jun 15, 2013, 10:20:52 AM6/15/13
to googl...@googlegroups.com
Comment by acas...@google.com:

I've added the features column for the 2.1 release - which includes
Multibindings.

googl...@googlecode.com

unread,
Aug 29, 2013, 12:40:30 PM8/29/13
to googl...@googlegroups.com
Comment by queen...@arcbees.com:

Why is injecting package private type not available anymore? I was using
this for GWT.create interfaces nested in my classes!

googl...@googlecode.com

unread,
Apr 29, 2015, 2:57:53 AM4/29/15
to googl...@googlegroups.com
Comment by zaharo...@gmail.com:

Guice 4.0 just released recently?
What's about GIN support?

googl...@googlecode.com

unread,
Apr 29, 2015, 2:58:53 AM4/29/15
to googl...@googlegroups.com
Comment by zaharo...@gmail.com:

Guice 4.0 just released recently! What's about GIN suport?
Reply all
Reply to author
Forward
0 new messages