HI I come from a background C#/.NET and have learned to work with a bit of Android.Now I am wana start to build a small app for fun and I tought to learn an IoC framework.After a bit of googeling I found roboguice.But I can not figure out how to integrate it.On .
NET I have worked with Ninject and Unity , and am looking to create a similar form of constructor injection that I got from those frameworks.
Here is what I have so far and what I think I have figured out:
This class represent the app bootstrapper and here is where I will register my dependency config class:
public class IOCApplication extends Application{
@Override
public void onCreate(){
super.onCreate();
RoboGuice.setBaseApplicationInjector(this, RoboGuice.DEFAULT_STAGE, RoboGuice.newDefaultRoboModule(this), new IOCModule());
}
}
This is the Dependency config class:
public class IOCModule implements Module{
@Override
public void configure(com.google.inject.Binder binder) {
binder.bind(ITest.class).to(Test.class);
}
}
In my AndroidManifest I have added this:
<application ... android:name="com.example.project2.IOCApplication">
This part I do not realy understad why I had to add but I am thinking it's something to tell Android that IOCApplication should be isntantiated first.
This is the clas my MainActivily class and I have added a constructor for it:
public ITest test;
public MainActivity(ITest test){
this.test = test;
}
When I try to runthis on my android device it kind of looks like the app is entering an infinite loop and I do not think ITest get's instantiated.
What am I doing wrong?