I've gone through the user guide and everything but yet I still don't understand exactly how to modify existing code to use Google Guice when trying to inject dependencies. So to make it easier I created this simple example and if someone could explain with this simple example I would really appreciate it!
Say I have a
public Class A {
private int count = 0;
public A() {
}
public int getCount() {
return count;
}
public void setCount(int newCount) {
this.count = newCount;
}
}
and another class
public Class B {
private A objectA;
public B() {
objectA = new A();
}
public void messWithCount() {
int tempCount = objectA.getCount();
objectA.setCount(tempCount+1);
}
}
So basically my question is: how would I go about using Google Guice to extract creation of objectA
in the constructor B()
and instead inject it as a dependency in Class B where it would amount to something like
@Inject
public B() {
}
and how would I actually inject an instance of A into it?