Guice newbie question: creating N objects on-demand

2008-10-16 Thread Andrew Clegg
Hey folks, I'm just getting started with Guice (and DI in general). I have a question, hope it's not too dense. I have a method that looks something like this in its first incarnation (_predictors is a collection): public boolean dispatch() { for( PredictorProfile predictor : _p

Re: Guice newbie question: creating N objects on-demand

2008-10-16 Thread Andrew Clegg
public DispatchHandler newInstance(PredictorProfile predictor) { >> return new DispatchHandler(predictor, d1, ...); >> } >> } >> } >> >> You could also use "Builder" instead of "Factory" depending on how you >> structure

Re: Guice newbie question: creating N objects on-demand

2008-10-16 Thread Andrew Clegg
ings to > be immutable myself. > > Bob > > On Thu, Oct 16, 2008 at 9:24 AM, Andrew Clegg <[EMAIL PROTECTED]> > wrote: >> >> Okay... You took me by surprise a bit, I was expecting something based >> on Provider. Like injecting a >> Provider as one of the a

Re: Guice newbie question: creating N objects on-demand

2008-10-16 Thread Andrew Clegg
2008/10/16 Bob Lee <[EMAIL PROTECTED]>: > That looks fine to me. You've effectively inverted the design, turning > DispatchHandler into a thread factory. Great, that's roughly how I was intending it to begin with, hence not wanting another level of indirection in there really. Nice one for putt

Re: Binding providers in the module

2008-10-20 Thread Andrew Clegg
. Hope it helps. > > Cheers, > Alen > > On 20 okt., 13:04, "Andrew Clegg" <[EMAIL PROTECTED]> wrote: >> Morning folks, >> >> I have a custom provider for creating SoapDispatchHandler objects, >> which implement an interface called DispatchH

Re: Binding providers in the module

2008-10-20 Thread Andrew Clegg
gt; >> >> > I don't think you shuld be conserning yourself with binding provider >> > directly. >> >> > bind(DispatchHandler.class).toProvider(SoapDispatchHandlerProvider.class); >> >> > now if you do >> >> > @Inject >> &g

Binding providers in the module

2008-10-20 Thread Andrew Clegg
Morning folks, I have a custom provider for creating SoapDispatchHandler objects, which implement an interface called DispatchHandler. I want to set up a binding in my module such that any reference to Provider is injected with an instance of SoapDispatchHandlerProvider, the provider class which

Re: Binding providers in the module

2008-10-20 Thread Andrew Clegg
Yep, working fine now, thanks Alen. This is my second week of Guice, expect more silly questions :-) 2008/10/20 Andrew Clegg <[EMAIL PROTECTED]>: > Aah! I didn't realise you could do that. I thought providers just > worked like this: > > // module > bind(

Guice injecting empty String unexpectedly

2008-10-28 Thread Andrew Clegg
Maybe I'm doing something stupid, but what's wrong with this picture: // In my module RealServicesModule bind( String.class ).annotatedWith( FuncNetVersionDependent.class ).toInstance( "http://cathdb.info/FuncNet_0_1/"; ); // A static member in my test class @Inject @FuncNetVersi

Re: Guice injecting empty String unexpectedly

2008-10-28 Thread Andrew Clegg
PS This is using old-skool Guice 1.0 release, I'm hesitant to upgrade while I'm still learning, but if this is a known issue then I can... Cheers. Andrew. 2008/10/28 Andrew Clegg <[EMAIL PROTECTED]>: > Maybe I'm doing something stupid, but what's wrong with this p

Re: Guice injecting empty String unexpectedly

2008-10-28 Thread Andrew Clegg
2008/10/28 Robbie Vanbrabant <[EMAIL PROTECTED]>: > You have to create the injector @BeforeClass gets called, and you need to You mean initialize it as a static member itself or something? private static Injector injector = Guice.createInjector( new RealServicesModule() ); Then do the @BeforeCl

Re: Where to find some examples programs for great beginner ?

2008-11-29 Thread Andrew Clegg
As another complete beginner (to dependency injection in general) I found the book really useful: http://books.google.com/books?id=0A0v45fHtHcC Andrew. 2008/11/29 Pierre8r <[EMAIL PROTECTED]>: > > Hello, > > Where to find some examples programs for great beginner ? > > Thanks, > > Pierre8r > >

Accidentally binding to an abstract class causes a NullPointerException (Guice 1.0)

2008-12-05 Thread Andrew Clegg
Morning folks, just FYI: I accidentally bound an interface to an abstract class (forgot to un-abstract it after some refactoring) and got an NPE in BindingBuilderImpl$FactoryProxy: com.google.inject.ProvisionException: Error while locating instance bound to info.cathdb.funcnet_0_1.sessiondb.Re

Re: Accidentally binding to an abstract class causes a NullPointerException (Guice 1.0)

2008-12-05 Thread Andrew Clegg
2008/12/5 Stuart McCulloch <[EMAIL PROTECTED]>: > > FYI, according to the issues list it has been fixed: > > http://code.google.com/p/google-guice/issues/detail?id=184 Whoops, my bad for not checking. Thanks. Andrew. --~--~-~--~~~---~--~~ You received this mess

Re: Can Guice be used to build flexible / variable object graphs?

2008-12-23 Thread Andrew Clegg
You can do this by binding List references annotated with a particular marker annotation to a specific implementation of List, which preloads itself with the required elements. e.g. Set up annotations called @FileMenu, @EditMenu ... and Guice can look for these and bind to the right preload

Re: I must really be screwing something up, what I want to do here shouldn't be this difficult...

2009-01-14 Thread Andrew Clegg
annotated with the appropriate annotations. Or I might have completely misunderstood the problem :-) Andrew. 2009/1/14 Andrew Clegg : > Are GuiSqlMapClientProvider and NdaSqlMapClientProvider supposed to be > singletons? You might want to try something like toInstance() method > describ

Re: I must really be screwing something up, what I want to do here shouldn't be this difficult...

2009-01-14 Thread Andrew Clegg
2009/1/14 Rick : > The problem(?) is that SqlMapClient.class is an object I don't have control > of it's an iBATIS class that just needs a config file sent to it. Different > DAOs I use (just two for instance) need a different load of that > SqlMapClient class. That's waht the provider was doing

Re: I must really be screwing something up, what I want to do here shouldn't be this difficult...

2009-01-14 Thread Andrew Clegg
2009/1/14 Rick : > I see, use a Module class instead of a Provider? I never thought of that. > That's where I was getting stumped - "where to do that work that initializes > the sqlMapClient instance that I'll need." I didn't think Modules were for > that sort of thing, but it looks pretty clean.

Posting to this list from secondary email address

2009-01-14 Thread Andrew Clegg
Hi, Does anyone know why I can't post to this group from a secondary, non-gmail email address? Google is aware that the address belongs to my account, because it shows as a secondary address here https://www.google.com/accounts/EditUserInfo and here https://www.google.com/accounts/EditUserInfo .

Re: Posting to this list from secondary email address

2009-01-14 Thread Andrew Clegg
2009/1/14 Rick : > I don't think google groups allow posting to them from a non gmail address. There were some last month from someone at @nrc-cnrc.gc.ca ... Andrew. -- New site launched: http://biotext.org.uk/ I am retiring my old email addresses. Please use firstn...@nervechannel.com where

Re: Posting to this list from secondary email address

2009-01-14 Thread Andrew Clegg
2009/1/14 Putrycz, Erik : > > Yes you just need to register your email as google account. Hmm, having tried various combinations, the only way to make it work if you're actually *using* gmail to send mail from your non-gmail address, is to subscribe both accounts to the list. Otherwise it thinks

Re: I must really be screwing something up, what I want to do here shouldn't be this difficult...

2009-01-14 Thread Andrew Clegg
2009/1/14 Rick : > Thanks Andrew! This worked perfectly. I owe you one. No probs :-) > Truthfully, I think this concept of using a Module to instantiate more than > one of the same type of object should be emphasized more in the docs, or > maybe in the wiki. I guess if you think of the Module

Re: Isn't using @ImplementedBy a bad idea?

2009-01-14 Thread Andrew Clegg
2009/1/14 Rick : > I'm curious, I like the fact that you can use annotations, but if you > annotate your interfaces with @ImplementedBy aren't you breaking the whole > concept of DI? I would think the point of using a DI framework is that if I > wanted I could quickly swap out the implementations

Re: I must really be screwing something up, what I want to do here shouldn't be this difficult...

2009-01-14 Thread Andrew Clegg
2009/1/14 Robbie Vanbrabant : > I think the more elegant solution (Guice 2.0) would be to use private > modules: > http://google-guice.googlecode.com/svn/trunk/latest-javadoc/com/google/inject/PrivateModule.html How stable is Guice 2.0? Is there an estimated release date? > Avoiding work in modu

Re: Guice equivalent for Spring afterPropertiesSet

2009-01-16 Thread Andrew Clegg
Simple answer: Stick to constructor injection. Then when the constructor actually starts running, you know all the injection is done. 2009/1/16 Kamran : > > Is it possible to call some method after an object is completely > injected with dependencies? At the moment I have to explicitly call > the

Correct way to inject dependencies into web service

2009-02-06 Thread Andrew Clegg
Hi folks, I'm looking for a bit of advice here... I'm building a JAX-WS Provider web service using the CXF toolkit. The Provider class is created by CXF (actually via Spring but I don't use Spring myself) via a no-arg constructor on starting the application. NB When I say Provider in this message

Re: Correct way to inject dependencies into web service

2009-02-06 Thread Andrew Clegg
PS I'm still using Guice 1.0 but I'm happy to upgrade if nearly-2.0 makes this easier... 2009/2/6 Andrew Clegg : > Hi folks, I'm looking for a bit of advice here... > > I'm building a JAX-WS Provider web service using the CXF toolkit. The > Provider class is cre

Re: Correct way to inject dependencies into web service

2009-02-09 Thread Andrew Clegg
but it doesn't do much so it doesn't really need to be. And the real web service provider can be tested with mocked-out dependencies without using Guice. If anyone has a better solution I'd be happy to hear it, but this seems to work pretty well. Andrew. 2009/2/6 Andrew Clegg : >