You could always expose a thin static wrapper over the injector so that
users don't have to know about the Guice modules or the injector for that
matter.  What I might do is this:


class ServiceCreator {
  public static <T> T getBar(Class<T> clz) {
    return Guice.createInjector(modules).getInstance(clz);
  }
}

The clients can decide how they want to consume something like this.  I'm
assuming that you're talking about existing applications that are NOT
currently using IoC.

Eric

On Tue, Jan 13, 2009 at 2:40 PM, rickcr <[email protected]> wrote:

>
> I'm wondering if maybe I should just force my end clients to rely on
> guice.. they'll need the guice jar in their lib anyway as a dependency
> for my jar to by used in their projects.
>
> I'm just not sure how others deal with this in their corporations? Is
> there an easy way to provide possibly one exposed delegate type class
> for the end users to interact with, and from their I bootstrap what I
> need in my jar?
>
> (This jar isn't going to be used in a Tibco project and possibly a few
> other ones. I wanted to isolate the end users as much as possible from
> configuration issues.)
>
> On Jan 13, 1:48 pm, rickcr <[email protected]> wrote:
> > I'm in the process of creating a persistence.jar that different
> > projects can use. The jar will mainly consist of service objects that
> > call daos. For example UserService will have getUser which calls a
> > userDao.getUser  method.
> >
> > I'm not so sure though that I want the external users of the jar to be
> > required to use Guice to bootstrap it with Guice.createInjector
> > (module).
> >
> > I don't really mind, if at the very end point that the user's deal
> > with, I code typical singletons, but I still want the daos injected by
> > Guice.
> >
> > So for example...
> >
> > public class AssociateService extends BaseService {
> >         private static final AssociateService instance = new
> AssociateService
> > ();
> >         private AssociateService() {}
> >         public static AssociateService getInstance() {
> >            return instance;
> >         }
> >
> >         AssociateDAO associateDAO;
> >
> >         @Inject
> >         public setAssociateDAO(AssociateDAO associateDAO) {
> >                 this.associateDAO = associateDAO;
> >         }
> >
> >         public Associate findByDmzID(String dmzID) throws Exception  {
> >                  return associateDAO.findByDmzID(dmzID);
> >         }
> >         //..
> >
> > }
> >
> > public abstract BaseService {
> >         static {
> >                 //COULD I JUST BOOTSTRAP HERE? which will make sure that
>  call
> >                 //to AssociateService.getInstance() will properly have
> the
> > AssociateDAO injected?
> >                Guice.createInjector(module)
> >         }
> >
> > }
> >
> > I'm just not sure the above would work out ok?
> >
>

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