Nitik,
Let me try to explain you what I understand here . Let us take the simple example from what documentation Scott has shared
- So this says ; when the model's adaptable is SlingHttpServletRequest , then when you try to inject getPropertyName() ; it will be return the property via resource method of the SlingHttpServletRequest object "request" like the below
request.getResource().getValueMap().get("propertyName", String.class)
That said , if you check the API SlingHttpServletRequest (Apache Sling Aggregate 5-incubator API) you can understand that a resource can be fetched from a request , but the vice versa is not possible .
So basically that means inject the value via resource API in SlingHttpServletRequest API.
I am not aware of a way to get a request object from a resource and hence I don't believe something like below is even possible
@Model(adaptables=Resource.class)
public class MyModel {
@Inject
@Via("request")
private String someObj;
}
For further reading the below section explains what all standard types are provided via while and how it is implemented
Apache Sling :: Sling Models
The other thing you can do is to adapt the SlingHttpServletRequest and get the resource from it
@Model(adaptables = SlingHttpServletRequest.class)
public class MyModel {
@Inject
SlingHttpServletRequest request;
@PostConstruct
protected void init() {
Resource resource = request.getResource() ;
}
}