Android Ioc RoboGuice(3) 使用介绍
Android Ioc RoboGuice(三) 使用介绍Ioc配置依赖:@InjectView (R.id.hello) TextView helloLabel @Inject
Android Ioc RoboGuice(三) 使用介绍
Ioc配置依赖:@InjectView (R.id.hello) TextView helloLabel; @InjectResource(R.drawable.icon) Drawable icon;@Inject LocationManager loc;
模块(Modules) 是Guice 构造Object Graph 的基本构造块,Guice中构造object Graph 的工作有被称为”Injector”的类来完成。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); } }