I am getting into Inversion of Control, specifically using Guice
and RoboGuice
for Android and I have a question.
I have a method call that returns a Resource (which is essentially an XML or JSON String).
public Resource getResource(){
// Some implementation details that call a web service and throw the result in a string...
String resource = ........
}
The Resource
class is really just a wrapped String
, so I figured it made sense to pass it in in the constructor, since it is an essential part of a Resource
object.
public class Resource{
Resource(String theXMLorJSON){
...
}
}
A couple of questions:
- How do I construct a new
Resource
in thegetResource
call? I would think that I want to use IoC and not callnew
in the method. - If another class takes a
Resource
in the constructor, how can I use theGuice
container to construct it when I need a dynamicString
at construction time? I just asked a similar question and believe there may be a specific way to handle this usingGuice
.
Thanks so much!