The use I expected was along these lines:
    router.attach(uriPattern, factory.finderFor(MyResource.class));
    // "route a request to uriPattern to whatever is bound to MyResource in
Guice"

In the very common case that MyResource is the concrete resource class you
want to use, you don't have to bind it explicitly to itself in a Guice
module.

Private helper methods would make this easier to read:

        router.attach("/policies/{id}", to(InsurancePolicyResource.class));
    ...
    private Finder to(Class<? extends Handler> resourceClass) {
        return getFactory().finderFor(resourceClass);
    }
    private synchronized FinderFactory getFactory() {
        if (this.finderFactory == null) {
            this.finderFactory = ... create FinderFactory here ...;
        }
        return this.finderFactory;
    }
    @GuardedBy("this") private FinderFactory finderFactory;

If, however, you have bound the same abstract resource type in different
ways for different annotations, you would use this approach:

    router.attach(uriPattern,
factory.finderFor(Key.get(AbstractResource.class, SomeAnnotation.class)));
    // "route a request to uriPattern to whatever is bound to
@SomeAnnotation AbstractResource in Guice"

I think this usage will be rare, but I didn't want to rule it out.

--tim

On Fri, Dec 19, 2008 at 11:41 AM, Brian Williams <bwilli...@archer-group.com
> wrote:

>  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*);
>
>
>
> Finder finder = factory.finderFor(Key.*get*(Handler.*class*,
> InjectableResource.*class*));
>
>
>
> router.attach("/policies", InsuredPolicyResource.*class*);
>
> router.attach("/policies/{id}", InsuredPolicyResource.*class*);
>
> router.attach("/vehicles", VehicleResource.*class*);
>
> router.attach("/vehicles/{id}", VehicleResource.*class*);
>
> router.attach("/garages", GarageResource.*class*);
>
> router.attach("/garages/{id}", GarageResource.*class*);
>
>
>
> *return* router;
>
>
>
> I'm not sure how I can create multiple finders that lookup the right
> resource to attach to the router. The "InjectableResource" above is just a
> tag annotation, but the example on the web page has one annotation for the
> one resource.
>
>
>
> If anyone has any suggestions or examples for specifying which Resource to
> grab from the finder, I'd really appreciate it.
>
> Thanks,
>
> Brian
>
>
>
> --
>
> Brian E. Williams
>
> Senior Application Developer
>
>
>
> The Archer Group
>
> 233 King Street
>
> Wilmington, DE 19801
>
>
>
> w: 302.429.9120 x225
>
> f: 302.429.8720
>
>
>
> http://www.archer-group.com
>
>
>

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

Reply via email to