-
Notifications
You must be signed in to change notification settings - Fork 3
Leverage Implicit Injection
Implicit Injection is a less verbose form of dependency injection which infers the ID using the field name. It's activated on an `IckleActivity` using `@InjectAll` which assumes all fields to be candidates for injection.
@InjectAll
@Fullscreen
@Layout(R.layout.act_login)
public class LoginActivity extends IckleActivity {
}To remove a field from being an injection candidate, annotated it with @IgnoreInjection.
@InjectAll
@Fullscreen
@Layout(R.layout.act_login)
public class LoginActivity extends IckleActivity {
@IgnoreInjection
private String TAG = LoginActivity.class.getSimpleName();
}####1. Injecting Views And Resources
To inject views and resources implicitly, simply mirror the view or resource ID in the field name.
@InjectAll
@Fullscreen
@Layout(R.layout.act_login)
public class LoginActivity extends IckleActivity {
private EditText edt_username;
private EditText edt_password;
private Button btn_login;
private Drawable login_banner;
private Animation fade_in;
@Layout(R.layout.section_forgot_password)
private ViewGroup forgotPassword;
...
}Use
@Layoutfor injecting layouts which exist outside the current context.
####2. Injecting System Services
To inject system services implicitly, mirror the name of the associated constant on Context in the field name.
@InjectAll
@Layout(R.layout.act_contact)
@Title(R.string.ttl_act_contact)
public class ContactActivity extends IckleActivity {
private TelephonyManager telephony_service;
...
}####3. Injecting Ickle Services
To inject Ickle Services implicitly, simply declare a member with the service contract.
@InjectAll
@Layout(R.layout.act_contact)
@Title(R.string.ttl_act_contact)
public class ContactActivity extends IckleActivity {
private BindManager bindManager;
...
}####4. Injecting Application Instances
To inject application instances implicitly, annotate the application contract or the custom application instance with @ApplicationContract.
######Contract
@ApplicationContract
public interface ApplicationService {
...
}######Implementation
public class ApplicationServiceImpl extends android.app.Application
implements ApplicationService {
...
}######Declaration
<manifest
...
<application
android:name="com.sample.app.ApplicationServiceImpl"
...
######Injection
@InjectAll
@Layout(R.layout.act_home)
@Title(R.string.ttl_act_home)
public class HomeActivity extends IckleActivity {
private ApplicationService app;
...
}####5. Injecting POJOs
To inject POJOs implicitly, annotate the POJO contract or the implementation with @Pojo.
######Contract
@Pojo(BasicAccountService.class)
public interface AccountService {
...
}######Implementation
public class BasicAccountService implements AccountService {
...
}######Injection
@InjectAll
@Fullscreen
@Layout(R.layout.act_login)
public class LoginActivity extends IckleActivity {
private AccountService accountService;
...
}