Hi Paul,
being able to return a class sounds really great!
Though, in our case we have something like a resource (Items) with path
"/items" and another resource (Item) with path "{itemId}". In the Item
resource we need access to the path parameter "itemId".
Is there any way to retrieve the value of "itemId" within Item if it is
instantiated by an ioc-container like spring?
Btw: I'm just starting with jsr311/jersey and like it very much -
congrats and thx a lot!
Cheers,
Martin
On Tue, 2008-02-19 at 12:24 +0100, Paul Sandoz wrote:
> Hi,
>
> One of the major pain points i have observed from developers is that
> sub-locators return objects and it is necessary to manually pass
> contextual information injected on the root resource classes to
> resources instantiated and returned by sub-locators.
>
> I have modified things in the trunk so that it is possible for a
> sub-locator to return a Class. For example:
>
> @Path("/parent")
> static public class Parent {
> @GET
> public String getMe() {
> return "parent";
> }
>
> @Path("child")
> public Class<Child> getChild() {
> return Child.class;
> }
> }
>
> static public class Child {
> @GET
> public String getMe() {
> return "child";
> }
> }
>
> The standard life-cycle mechanisms (singleton or per-request) should all
> work as before and Jersey will defer to a component provider for
> instantiating the returned class. So it should be much easier to work
> with Spring.
>
>
> Another fix i am considering is allowing injection of ComponentProvider:
>
> @Path("/parent")
> static public class Parent {
> @Context ComponentProvider cp;
>
> @GET
> public String getMe() {
> return "parent";
> }
>
> @Path("child")
> public Child getChild() {
> Child c = new Child();
> // Spring does not support this :-(
> cp.inject(c);
> return c;
> }
> }
>
> @Path("/parent")
> static public class Parent {
> @Context ComponentProvider cp;
>
> @GET
> public String getMe() {
> return "parent";
> }
>
> @Path("child")
> public Child getChild() {
> return cp.getInstance(c);
> }
> }
>
> which allows the application to have some extra control over the
> instance before it is returned. Is this something people would find useful?
>
> Thanks,
> Paul.
>