Hi Santiago,
I mean injectable into a CDI managed bean not created by the JAX-RS runtime.
So that it would be possible to write:
@Stateless
@Path("shopping_cart")
public class ShoppingCartResource {
@Inject
BookstoreUriBuilder uriBuilder;
@GET
public ShoppingCart get() {
...
uriBuilder.forBook(book);
...
}
}
// Dependent scoped CDI bean
public class BookstoreUriBuilder {
@Inject
UriInfo uriInfo;
public URI forBook(Book book) {
return uriInfo...
}
}
Injection of UriInfo with @Context is only possible into JAX-RS
resources -- according to Chapter 3.2 -- or am I missing something here?
Cheers,
Sebastian
On 02/02/2016 03:01 PM, Santiago Pericasgeertsen wrote:
> Sebastian,
>
> UriInfo should already be injectable using @Context.
>
> — Santiago
>
>> On Feb 1, 2016, at 3:56 PM, Sebastian Daschner <java_at_sebastian-daschner.de> wrote:
>>
>> Hi experts,
>>
>> Thanks for the work done so far.
>>
>> We had the case in projects that we wanted to construct URIs based on
>> UriInfo without wanting to pass the current UriInfo into other
>> (dedicated helper) classes.
>>
>> Do you think it's feasible to enable the request scoped UriInfo (plus
>> maybe others) for CDI injection, in order to decouple potential URI
>> construction classes from the JAX-RS resources?
>>
>> So something like follows would be possible (to call the method from any
>> component):
>>
>> public class BookstoreUriBuilder {
>>
>> @Inject
>> UriInfo uriInfo;
>>
>> public URI forBook(Book book) {
>> return uriInfo.getBaseUriBuilder()
>> .path(BooksResource.class)
>> .path(BooksResource.class, "getBook")
>> .build(book.getId());
>> }
>>
>> }
>>
>> WDYT?
>>
>> Cheers,
>> Sebastian