dropwizard-guicey icon indicating copy to clipboard operation
dropwizard-guicey copied to clipboard

Supporting sub resource locators

Open muliyul opened this issue 3 years ago • 4 comments

Consider it a feature request.

muliyul avatar Nov 24 '22 00:11 muliyul

Can you please show a simple use case?

I read the docs about locators, but I'm not sure it's possible to support them. At least, with h2 involved. Maybe, if sub-resource would be injected directly as a simple guice-managed bean it would be possible to use it as sub resource, but it must be verified:

@Inject SubResource sub;

@Path("sub") public class<SubResource> getSub() {
    return sub;
}

Anyway, need to know what was the exact problem in your case and then I could look for possible solutiuon.

xvik avatar Nov 24 '22 05:11 xvik

The problem:

// Kotlin
// API module
@Path("/users")
interface UsersResource {
 @GET
 fun list(): List<User>

 @Path("/{id}")
 fun get(@PathParam("id") id: String): UserResource
}

interface UserResource {
 @GET
 fun get(): User
}


// Implementation (dropwizard)
class MyUserResource @Inject constructor(
 private val injector: Injector
): UsersResource {
 override fun list(): List<User> { ... }

 // this is boilerplate. can we get rid of it somehow?
 override fun get(id: String): UserResource = 
  UserResource(id).apply { injector.injectMembers(this) }
}

muliyul avatar Nov 24 '22 11:11 muliyul

Thank you for the example. I will look what I can do

xvik avatar Nov 24 '22 11:11 xvik

Thanks. I guess an alternative would be to support sub resources (like your example) with the Class object syntax.

muliyul avatar Nov 24 '22 11:11 muliyul