If you'd like to look through some more large code bases, we use Guice for
LimeWire.  The code is available from www.limewire.org.  We use two separate
injectors, one for the core & another for UI.  (And, of course, lots of
throwaway child injectors for AssistedInject.)

Sam

On Fri, Aug 7, 2009 at 1:36 PM, Brandon Atkinson <
[email protected]> wrote:

> Adrian,
> That does help, especially with the reference to the jclouds project.  A
> real world example will help greatly.
> Thanks,
> -Brandon
>
>
> On Fri, Aug 7, 2009 at 12:51 PM, Adrian Cole <[email protected]> wrote:
>
>> Hi, Brandon.
>>
>> jclouds is a heavy user of guice and internally uses about 350 classes
>> (excluding unit tests).  The way we work is that we create a context into
>> our framework, which implies creation of an injector.  Where needed
>> (rarely), Injectors are injected into classes.
>>
>> Getting this context is performed one of two ways:
>>
>> 1.  Builder that accepts external parameters like Guice constants or other
>> Guice Modules needed, then builds an injector from them.
>>
>> Ex.
>>
>>>    public Injector buildInjector() {
>>>
>>>       useDefaultPortIfNotPresent(properties);
>>>
>>>       addLoggingModuleIfNotPresent(modules);
>>>
>>>       addParserModuleIfNotPresent(modules);
>>>
>>>       addConnectionModuleIfNotPresent(modules);
>>>
>>>       addHttpModuleIfNeededAndNotPresent(modules);
>>>
>>>       addExecutorServiceIfNotPresent(modules);
>>>
>>>       modules.add(new AbstractModule() {
>>>          @Override
>>>          protected void configure() {
>>>             Names.bindProperties(binder(), checkNotNull(properties,
>>> "properties"));
>>>          }
>>>       });
>>>       addContextModule(modules);
>>>
>>> *      return Guice.createInjector(modules);*
>>>    }
>>>
>>
>> 2.  Static factory method that creates a context with minimum input using
>> the above builder.
>>
>>   * public static S3Context createS3Context(String awsAccessKeyId, String
>>> awsSecretAccessKey,
>>>             Module... modules)* {
>>>       return S3ContextBuilder.newBuilder(awsAccessKeyId,
>>> awsSecretAccessKey).withModules(modules)
>>>                .buildContext();
>>>    }
>>>
>>
>>
>> I hope this helps.
>> Cheers,
>> -Adrian
>> jclouds <http://code.google.com/p/jclouds/>
>>
>>
>> On Fri, Aug 7, 2009 at 7:56 AM, Brandon Atkinson <
>> [email protected]> wrote:
>>
>>> I'm looking for a little guidance on cleanly architecting a Guice based
>>> project.
>>>
>>> I'm new to DI and Guice, but after reading the docs and the Apress Guice
>>> book, I'm still a bit confused about how to architect applications to use
>>> Injectors properly.  Is it common practice to have only a single Injector
>>> for an application, and pass the Injector around?  If so, should I be
>>> injecting the injector, or using an application wide static factory method?
>>> What might be helpful is an example of a cleanly implemented Guice
>>> project that is larger than two or three classes.
>>>
>>> Looking for a little guidance...
>>>
>>> -Brandon
>>>
>>>
>>>
>>
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to