The project is set up with CDI 2.0 (specifically Weld 3.0.4). Now I want to have a service accessing and caching an external REST interface.
For the sake of simplicity let's assume this REST interface is returning Json objects for given numeric identifiers, speaking in Java: service.getProduct(int productKey)
.
What is the 'CDI way' to write such a service, specifically the scope and the instantiation of Product
objects (which are returned by the service)?
(Incomplete) Pseudo code:
public class ProductService {
public Product getProduct(int productKey) {
String json = rest.get(productKey);
return new Product(json);
}
}
...
@Produces
public Product create(int productKey) {
return new Product(productKey);
}
From my research producer methods do not support runtime parameters. So how to bring these two parts together?