//dagger2
implementation 'com.google.dagger:dagger:x.xx'
implementation 'com.google.dagger:dagger-android-support:x.xx'
annotationProcessor 'com.google.dagger:dagger-compiler:x.xx'
annotationProcessor 'com.google.dagger:dagger-android-processor:x.xx'
User's Guide _ https://google.github.io/dagger/users-guide
Declaring Dependencies
@Inject
Satisfying Dependencies
@Provides
@Module
Building the Graph
@Component
@Component.Builder
Singletons and Scoped Bindings
@Singleton
@Reusable
Lazy injections
Lazy<T>
Qualifiers
@Qualifier
@Named
Optional bindings
@BindsOptionalOf
Binding Instances
@BindsInstance
MultiBindings _ https://google.github.io/dagger/multibindings
Set multibindings
@IntoSet
@ElementsIntoSet
Map multibindings
@IntoMap
@MapKey
Declaring multibindings
@Multibinds
SubComponent _ https://google.github.io/dagger/subcomponents
Declaring a subcomponent
@Subcomponent
@Subcomponent.Builder
Dagger & Android _ https://google.github.io/dagger/android
Recommended Proguard Settings
Injecting Activity objects
AndroidInjectionModule
AndroidInjector<YourActivity>
AndroidInjector.Factory<YourActivity>
@Binds
@ContributesAndroidInjector
HasActivityInjector
DispatchingAndroidInjector<Activity>
Injecting Fragment objects
HasFragmentInjector
BaseFramework Types
DaggerActivity
DaggerFragment
DaggerApplication
DaggerService
DaggerIntentService
DaggerBroadcastReceiver
DaggerContentProvider
Tutorial_Blog(part1) _ https://blog.mindorks.com/introduction-to-dagger-2-using-dependency-injection-in-android-part-1-223289c2a01b
Tutorial_Blog(part2) _ https://blog.mindorks.com/introduction-to-dagger-2-using-dependency-injection-in-android-part-2-b55857911bcd
Dagger2 Annotations @Binds & @ContributesAndroidInjector _ https://proandroiddev.com/dagger-2-annotations-binds-contributesandroidinjector-a09e6a57758f
Efficient Using 한글 블로그 _ https://kaidroid.me/post/android-dagger-dependency-injection/
--
di란?
ㄴ참조 ) https://medium.com/@lazysoul/dependency-injection%EC%9D%B4%EB%9E%80-7ff65bdf624
객체 간의 의존관계를 객체-객체 (tight coupling)가 아닌 외부에서 객체를 생성하고 전달해 줌(loose coupling)으로 써 객체 간의 의존성 제거 및 결합도를 낮추는 것
장점
1. 모듈간의 의존성이 낮아져 유지보수에 좋다.
2. 모듈간의 의존성이 낮아져 코드 재사용이 좋다. ( 기능별로 분리를 잘 한경우 )
3. 테스트 하기 좋다.
Android context의 영향을 많이 받는 플랫폼이라고 할 수 있다.
Activity LifeCycle에 따라 자원을 생성하고 사용할 수 있다. 즉 Activity, Fragment 내에서 선언된고 사용되는 Instance들은 Activity, Fragment에 영향을 받는다는 소리
Instance가 내부의 영향을 받는다면, 같은 Instance 라도 다른 환경에서 다르게 동작 할 수 있다.
하지만 항상 같은 환경에서 Instance를 생성, Activity, Fragment 에서는 생성된 Instance를 받아서 사용만 한다면 내부 환경과 상관없이 같은 동작을 하며, 범용적으로 재사용 할 수 있다.
DI ( Dependency Injection )
Component는 Activity A와 Activity B에게 각각 필요한 Instance를 선언한다.
Component는 요청한 Instance들을 Injection 해준다.
내부에서 Instance 를 생성하지 않고 Component를 통해 필요한 Instance를 주입받는다.
-> 의존성이 느슨해짐
study - https://developer.android.com/training/dependency-injection/dagger-basics