Re: create instance of class with guice

2010-05-10 Thread Philippe Beaudoin
You can use non-empty constructors with guice, just annotate it with @Inject to say that the construction parameters should be injected. In this case, however, I suspect that you want to provide the map as a parameter, in which case you should check out assisted injection: http://code.google.com/p/

Re: Do @SessionScoped objects need to be thread safe? And @RequestScoped?

2010-05-15 Thread Philippe Beaudoin
Forget this, just found the answer in the doc: http://code.google.com/p/google-guice/wiki/Scopes#Scopes_and_Concurrency Cheers, Philippe On Sat, May 15, 2010 at 3:07 PM, PhilBeaudoin wrote: > From my (admittedly limited) understanding of servlet container > mechanics, I understand that diff

Re: Circular dependencies in Guice

2010-10-04 Thread Philippe Beaudoin
Maybe a stupid answer, but have you tried injecting a Provider<> in one of the two classes, instead of directly injecting the class? Philippe On Mon, Oct 4, 2010 at 10:44 AM, Roman wrote: > Hi > I have a very strange problem , that no one could explain me. > So here is the problem. I have a c

Re: Custom just-in-time bindings?

2010-10-13 Thread Philippe Beaudoin
Thanks Dhanji, Following your recommendation I have tried to use TypeListeners to do this. Unfortunately, it looks like TypeListeners are called after the type's injected constructor has been scanned. As a result, if a constructor parameter is not bound my TypeListener is never fired. This prevent

Re: how to use optional injection with JSR330

2010-10-18 Thread Philippe Beaudoin
I've been looking at the Guice source for a replacement and found nothing. From what I've seen, if you're using JSR330 you don't have access to optional injection. :( Philippe On Mon, Oct 18, 2010 at 3:24 AM, Mingfai wrote: > hi, > > What's the equivalent of the "optional" value of @com.google

Re: Is a static factory the only way?

2010-11-03 Thread Philippe Beaudoin
This brings another question, however. How do you access the injector? I've tried injecting it but Guice complains that I cannot do that. Cheers, Philippe On Wed, Nov 3, 2010 at 8:58 PM, Kartik Kumar wrote: > If you have a reference to already instantiated object, can't you use > Injector#in

Re: Is a static factory the only way?

2010-11-03 Thread Philippe Beaudoin
@Fred. Strange, for some reason I remember getting an error message when trying to do that. I just tried again and it worked. On Wed, Nov 3, 2010 at 10:13 PM, Fred Faber wrote: > Yes, though Injector::injectMembers will of course only work if you have a > handle on the Injector. > > If you have a

Re: Unexpected: field injection in a provider instance works

2010-11-04 Thread Philippe Beaudoin
Just to come back on one of my questions: is injection automatically performed on the fields and methods of instances bound with toInstance()? Thanks for pointing out the MembersInjector. In this case I don't think I can use it however, for two reasons. Tell me if I'm wrong: 1) My SpyProvider is g

Re: Unexpected: field injection in a provider instance works

2010-11-04 Thread Philippe Beaudoin
On Thu, Nov 4, 2010 at 12:01 PM, Sam Berlin wrote: > On Thu, Nov 4, 2010 at 1:00 PM, Philippe Beaudoin > wrote: >> >> Just to come back on one of my questions: is injection automatically >> performed on the fields and methods of instances bound with >> toIns

Re: Unexpected: field injection in a provider instance works

2010-11-04 Thread Philippe Beaudoin
> Good catch.  It technically isn't needed in my example.  But, consider the > case where it's not split between Foo -> FooImpl, or if FooImpl was scoped > (as, say, a @Singleton annotation on FooImpl).  If it had a scoping > annotation, toConstructor basically ignores that scope.  For concrete > c

Re: understanding better the constant binding and type conversion

2010-11-05 Thread Philippe Beaudoin
I'm actually surprised you can inject a String into a Boolean (your second binding). Out of curiosity, is there any reason why you wouldn't do: binder.bind(Key.get(Boolean.class, Names.Named("myconfig.autoclose"))).toProvider(new Provider() { public Boolean get() {

Re: understanding better the constant binding and type conversion

2010-11-05 Thread Philippe Beaudoin
Thanks for the explanation Simone, just learned one more feature of Guice today! Also, sorry for my silly reply. :) Philippe On Fri, Nov 5, 2010 at 12:41 PM, Simone Tripodi wrote: > @Philippe > Guice uses an extensible way to convert Strings to > primitives/primitives wrappers/Enums and user d

Re: Serve static files with guice servlet

2010-11-19 Thread Philippe Beaudoin
I ran into a similar problem before, which I solved by updating my deployment descriptor to serve these files as static. In my case I was using AppEngine and the process is described here: http://code.google.com/appengine/docs/java/config/appconfig.html#Static_Files_and_Resource_Files I would b

Re: binding generic methods 2

2010-11-23 Thread Philippe Beaudoin
It looks to me you should write your own factory, containing a: Map> Where StoreEntityClassInfo contains both the store class and the entity class. Your factory would then have a: create(Class storeClass, Class entityClass); The last thing you need to do is register all your Adapter classes t

Re: Inject type parameter

2011-01-21 Thread Philippe Beaudoin
Assuming you want to do something like that: @Inject Class theClass; And you want it injected with Class, where SomeSubClass extends SomeClass, then you can do: bind(new TypeLiteral>{}).toInstance(SomeSubClass.class.getClass()); Cheers, Philippe On Fri, Jan 21, 2011 at 10:26 AM, Sam Berli

Re: Inject type parameter

2011-01-21 Thread Philippe Beaudoin
I forgot some parenthesis: bind(new TypeLiteral>(){}).toInstance(SomeSubClass.class.getClass()); On Fri, Jan 21, 2011 at 11:42 AM, Philippe Beaudoin wrote: > Assuming you want to do something like that: > > @Inject Class theClass; > > And you want it injected with Class,

Re: [google-gin] Re: Allowing scope annotations on abstract types?

2011-01-27 Thread Philippe Beaudoin
Thanks Thomas for the idea. It's an excellent one and we should definitely pursue it in gin. However, I'd like to probe the Guice developers on this a little more as I feel that the ability to annotate abstract types with a scope could be useful in other contexts as well. For example I'm using Gui

Re: Allowing scope annotations on abstract types?

2011-01-27 Thread Philippe Beaudoin
A couple of things: 1) MyInterface.class could actually be MyAbstractClass.class 2) The instance returned by GWT.create is not necessarily stateless. So, even though both objects are equal upon creation, you can manipulate them afterward. As a result, you don't want both calls to GWT.create to retu

Re: season dependent promos

2011-02-01 Thread Philippe Beaudoin
I have been using factories to do this. Something like: class PromoFactory { @Inject Provider springPromo; @Inject Provider winterPromo; Promo getPromo(Season season) { if( season == Season.Winter ) return winterPromo; return springPromo; } } Then inject the PromoFactory.

Re: One object per {Foo,Bar} pair

2011-02-14 Thread Philippe Beaudoin
Now, from your problem description, I'm not entirely sure how you specify your zip and brands. If you were planning to use AssistedInject but want to make sure that two different calls to the create method return the same instance when zip & brand are the same then you will probably have to build y

Re: Module versus AbstractModule

2011-02-16 Thread Philippe Beaudoin
On Wed, Feb 16, 2011 at 5:25 AM, Thomas Broyer wrote: > The best of both worlds is IMO to provide both an interface and a support > class and suggest people to preferably extend the abstract class (see for > instance the warning in the javadoc for > javax.lang.model.element.ElementVisitor; others

Re: Module versus AbstractModule

2011-02-16 Thread Philippe Beaudoin
by using @ImplementedBy.  But it > unnecessarily ties the API to the implementation, which is an even worse > transgression IMO. >  sam > > On Wed, Feb 16, 2011 at 9:04 AM, Philippe Beaudoin > wrote: >> >> On Wed, Feb 16, 2011 at 5:25 AM, Thomas Broyer wrote: >&

Re: @Provides , Provider

2011-02-16 Thread Philippe Beaudoin
*Copying the answer I gave to the dev group, as it should have been here...* Injecting a Provider lets you instantiate Foo multiple times by calling providerFoo.get(). The way Foo is generated is either: 1) The "default Guice way", if you bind(Foo.class).to(FooImpl.class) 2) Your custom way if yo

Re: Guice Conference

2011-02-18 Thread Philippe Beaudoin
We need GUG. Guice User Groups. I'll run mine from Montreal. :) -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsub

Re: is it possible to use Guice Multibindings feature in Google App Engine ?

2011-02-25 Thread Philippe Beaudoin
I believe it is. I've built the equivalent of multibindings manually (by binding various implementations using unique annotations) and it works fine. I can't see why multibindings would do anything non-GAE friendly. -- You received this message because you are subscribed to the Google Groups "

Re: not sure which one to choose GuiceBerry or AtUnit ?

2011-02-25 Thread Philippe Beaudoin
You can also check out jukito: http://jukito.org -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegr

Re: A little framework for JUnit + Guice

2011-02-28 Thread Philippe Beaudoin
I've open sourced my own take on a similar problem: http://jukito.org And of course there is Guiceberry doing something like that too... -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to google-guice@googleg

Re: A little framework for JUnit + Guice

2011-03-03 Thread Philippe Beaudoin
Really, the biggest advantage of Jukito is in the goodies it give you. Since you're using injection, you can easily have automocking... So Jukito does exactly that: each time an unbound interface is found it mocks it. The tests are a lot less brittle as a result. Something else Jukito gives you

Re: Custom just-in-time bindings?

2011-03-07 Thread Philippe Beaudoin
I think the standard way to do that is to use Guice's SPI to inspect non-bound types and provide the bindings yourself. I've used a much more complex method in http://jukito.org but I plan to reimplement all that with the SPI. Cheers, Philippe -- You received this message because you are

Re: GuiceCon showcase

2011-03-16 Thread Philippe Beaudoin
Can't make it to GuiceCon but I have this nice Guice extension for testing (in the spirit of Guiceberry, but for unit tests and automocking), which would be probably a good candidate for a quick demo, or to include in a list somewhere if you have such a thing... I would really have loved to join

Re: GuiceCon showcase

2011-03-16 Thread Philippe Beaudoin
Somehow it garbled the developers name: philippe.beaudoin christian.goudreau On Wednesday, March 16, 2011 10:51:45 AM UTC-7, Philippe Beaudoin wrote: > > Can't make it to GuiceCon but I have this nice Guice extension for testing > (in the spirit of Guiceberry, but for

Re: Custom just-in-time bindings?

2011-03-17 Thread Philippe Beaudoin
BTW, I commited the new code using SPI to jukito's trunk. Much simpler, and I get better error reports to boot! :) -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to google-guice@googlegroups.com. To unsubscrib

Re: Custom just-in-time bindings?

2011-03-17 Thread Philippe Beaudoin
On Thursday, March 17, 2011 5:28:48 AM UTC-7, Witold Szczerba wrote: > > Thanks for response, guys. The only problem is that your solutions are > pre-injector construction, but in my case I have to provide Injector > first and then be prepared for handling dependencies which were not > mentioned in

Re: Does Guice 2.0 work in Android 1.5

2011-03-17 Thread Philippe Beaudoin
Never did any Android work, but I think I remember reading that Andoid does not work with Guice AOP. Did you use the no-AOP version of Guice? Cheers, Philippe -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send emai

Re: Announcing Guice 3.0

2011-03-25 Thread Philippe Beaudoin
Congrats on the release! Guice is a great tool! BTW, how was the GuiceCon? -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to google-guice@googlegroups.com. To unsubscribe from this group, send email to google