Android Ioc RoboGuice(三) 使用介绍
- Ioc配置依赖:
- @InjectView (R.id.hello) TextView helloLabel; @InjectResource(R.drawable.icon) Drawable icon;@Inject LocationManager loc;
- Guice在模块为AbstractMoudule 的子类,而RoboGuice在模块为AbstractAndroidModule的子类。RoboGuice利用 Injector 来创建所依赖的对象,而Injector 为参照Module 中定义的Bindings来构造类于类之间的关系图。如果在某些情况下,如果你想直接使用Injector ,可以使用RoboActivity 的getInjector().比如
Injector injector=getInjector(); LocationManager loc = injector.getInstance(LocationManager.class);例子
public class SayModule extends AbstractAndroidModule{ @Override protected void configure() { bind(ISayService.class).to(SayHello.class); } }