Android Ioc RoboGuice (3) Introduction

Source: Internet
Author: User

Ioc configuration dependency:
@ InjectView (R. id. hello) TextView helloLabel;
@ InjectResource (R. drawable. icon) Drawable icon;
@ Inject LocationManager loc;
The module is the basic construction block for Guice to construct the Object Graph. The construction of the object Graph in Guice is completed by a class called "Injector.
Guice is a subclass of AbstractMoudule in the module, while RoboGuice is a subclass of AbstractAndroidModule in the module. RoboGuice uses Injector to create the dependent object, and Injector constructs the relationship diagram between classes by referring to the Bindings defined in Module. In some cases, if you want to use Injector directly, you can use getInjector () of RoboActivity ().
For example
[Java]
Injector injector = getInjector ();
LocationManager loc = injector. getInstance (LocationManager. class );
Example
[Java]
Public class SayModule extends AbstractAndroidModule {
@ Override protected void configure (){
Bind (ISayService. class). to (SayHello. class );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.