Yes, Guice can be used in the model that an Injector represents the
container in which objects of an app are configured and instantiated.
 That's a good way to go for a large set of cases.

An extension thereof is to use Guice to handle lifecycles as well.  To
handle an initialization-based lifecycle, it's convenient to use the
Service<http://code.google.com/p/guava-libraries/source/browse/trunk/src/com/google/common/base/Service.java?r=74>class,
and especially the
AbstractService<http://www.google.com/codesearch/p?hl=en#UKMs0lhE9bg/trunk/src/com/google/common/util/concurrent/AbstractService.java&q=AbstractService%20package:http://guava-libraries%5C.googlecode%5C.com&sa=N&cd=1&ct=rc>template.
  These classes are included in the Google
Guava <http://code.google.com/p/guava-libraries/>libraries.

A basic pattern to follow is to create a Set<Service> using a multibinder,
and then inject that into your main class or an application entry point.
 Something as simple as that typically does the trick.  This is preferred
over using initialization in modules because of the intrinsic multithreading
you can achieve with AbstractService subclasses.

Fred


On Mon, May 2, 2011 at 11:50 AM, Josh Kamau <[email protected]> wrote:

> This is my view;
>
> Guice is a just a container. So all you need is to instantiate the
> container : Injector injector = Guice.createInjector(...Modules) , Then get
> your objects from the injector using injector.getInstance(MyClass.class);.
> In most cases, other frameworks instantiate guice and get the objects
> without you having to do that.
>
> Josh.
>
>
> On Mon, May 2, 2011 at 5:58 PM, mwaschkowski <[email protected]>wrote:
>
>> Hi,
>>
>> I've searched the forum and checked the faq, but didn't see a mention
>> anywhere. I'm assuming that guice will just wire up my objects and
>> that application state initialization code should go somewhere else
>> (like an 'ApplicationSetup' class) that gets called after guice is
>> done wiring up objects? Or is there a feature within guice that I
>> should be using to do this?
>>
>> Thanks!
>>
>> Mark
>>
>> --
>> 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.
>>
>>
>  --
> 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.
>

-- 
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