Hi Brian,

I've been using Guice for a while now. Was a bit tough getting started, but now 
is working quite well. I didn't go down the path of using finders. With our set 
up we generally have collections of items and then their entities (as is pretty 
standard). 

I started by creating an abstract resource class (imaginatively called 
"AbstractResource") than extended the Restlet Resource class. This included a 
static Injector field. Below this are the Collection and Entity resource 
classes. All of the resource classes will extend one of these three classes, 
and all have their own Interfaces.

When the program starts it creates the injector, and then explictly sets the 
Injector for AbstractResource, so that this is available on the "other side" of 
Restlet creating Resources. Whenever Restlet creates the new instance of a 
resource class one of the first things done by AbstractResource is to 
injectMembers into itself using the static injector. Ie Guice is used to set up 
the environment and start the Restlet Server running, then Restlet handles 
creating the correct resource, and then Guice continues with the work by using 
the original Injector.

The advantage is I can use then standard @ImplementedBy and @Inject 
annotations, and testing is just as easy as ever.

If you want to see some code (or some clarification on these ramblings), I can 
send some through (working on some tidying up now).

AJ

National Poisons Centre,
New Zealand

-----Original Message-----
From: Brian Williams [mailto:bwilli...@archer-group.com]
Sent: Sat 12/20/2008 5:41 AM
To: discuss@restlet.tigris.org
Subject: Getting Restlet resources injected with Guice
 
Hi Everyone.

I'm attempting to use Guice with Restlet to inject session beans from EJB3
so that unit and module testing will be easier down the road. I found this
helpful site with some code examples for getting started on this:

http://tembrel.blogspot.com/2008/07/resource-dependency-injection-in.html

 

However, now I'm at the part where I want to attach multiple routers to
different paths of my app. So my application looks something like:

 

FinderFactory factory = RestletGuice.createInjector(new
DelegateModule()).getInstance(FinderFactory.class);

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=988546

<<attachment: winmail.dat>>

Reply via email to