File tree 14 files changed +139
-16
lines changed
java/com/mindorks/dagger/multi/module/main
java/com/mindorks/sample/feature/three
14 files changed +139
-16
lines changed Original file line number Diff line number Diff line change 1
- # Dagger Multi- Module Android
2
- Learn to use dagger for dependency management in a multi- module app
1
+ # Dagger Dynamic Feature Module Android
2
+ Learn to use dagger for dependency management in a dynamic feature module app
3
3
4
4
[ ![ MindOrks] ( https://img.shields.io/badge/mindorks-opensource-blue.svg )] ( https://mindorks.com/open-source-projects )
5
5
[ ![ MindOrks Community] ( https://img.shields.io/badge/join-community-blue.svg )] ( https://mindorks.com/join-community )
6
6
7
7
<p align =" center " >
8
- <img src="https://raw.githubusercontent. com/MindorksOpenSource/Dagger-Multi-Module-Android/master/art/dagger-github .png">
8
+ <img src="https://s3.ap-south-1.amazonaws. com/mindorks-server-uploads/dynamic-feature-module-banner-f27f94e8e526888d .png">
9
9
</p >
10
10
11
11
## About this Open Source Project
12
- This open-source project is for you(community). In this project you will learn about how to use dagger for dependency management in a multi-module app.
13
- ### [ You can find the blog to learn about Using Dagger in Multi-Module Architecture here] ( https://blog.mindorks.com/dagger-in-a-multi-module-project )
14
- ## Project Structure
15
- <p align =" start " >
16
- <img src="https://raw.githubusercontent.com/MindorksOpenSource/Dagger-Multi-Module-Android/master/art/project-structure.png">
17
- <img src="https://s3.ap-south-1.amazonaws.com/mindorks-server-uploads/feature-dependenct-base-d29d996b697942a8.jpg">
18
- </p >
12
+ This open-source project is for you(community). In this project you will learn about how to use dagger for dependency management in a multi-module app using dynamic feature module.
19
13
20
14
## Explore Android Online Tutorials and Courses To Learn More by MindOrks
21
15
* [ Android Tutorial] ( https://mindorks.com/android-tutorial ) - All Free Android Tutorials by MindOrks
Original file line number Diff line number Diff line change @@ -24,16 +24,17 @@ android {
24
24
}
25
25
}
26
26
27
+ dynamicFeatures = [" :featureThree" ]
27
28
}
28
29
29
30
dependencies {
30
31
implementation fileTree(dir : ' libs' , include : [' *.jar' ])
31
32
implementation " org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version "
32
- implementation ' androidx.appcompat:appcompat:1.1.0'
33
- implementation ' androidx.core:core-ktx:1.2.0'
34
- implementation ' androidx.constraintlayout:constraintlayout:1.1.3'
33
+ api ' androidx.appcompat:appcompat:1.1.0'
34
+ api ' androidx.core:core-ktx:1.2.0'
35
+ api ' androidx.constraintlayout:constraintlayout:1.1.3'
35
36
36
- implementation " com.google.dagger:dagger:2.27"
37
+ api " com.google.dagger:dagger:2.27"
37
38
kapt " com.google.dagger:dagger-compiler:2.27"
38
39
39
40
implementation project(' :base' )
@@ -43,4 +44,5 @@ dependencies {
43
44
testImplementation ' junit:junit:4.12'
44
45
androidTestImplementation ' androidx.test.ext:junit:1.1.1'
45
46
androidTestImplementation ' androidx.test.espresso:espresso-core:3.2.0'
47
+ api " org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version "
46
48
}
Original file line number Diff line number Diff line change @@ -30,7 +30,11 @@ class MainActivity : AppCompatActivity() {
30
30
.build()
31
31
.inject(this )
32
32
Log .d(" DaggerSample_Main" , databaseService.toString())
33
- startActivity(Intent (this ,FeatureOneActivity ::class .java))
33
+ // startActivity(Intent(this,FeatureOneActivity::class.java))
34
34
35
+ val intent = Intent ().setClassName(this , " com.mindorks.sample.feature.three.FeatureThreeActivity" )
36
+ startActivity(intent)
35
37
}
38
+
39
+
36
40
}
Original file line number Diff line number Diff line change 1
1
<resources >
2
2
<string name =" app_name" >Dagger-Multi-Module-Android-Example</string >
3
+ <string name =" title_feature_three" >feature-three</string >
3
4
</resources >
Original file line number Diff line number Diff line change @@ -32,8 +32,8 @@ dependencies {
32
32
implementation ' androidx.appcompat:appcompat:1.1.0'
33
33
implementation ' androidx.core:core-ktx:1.2.0'
34
34
implementation " com.google.dagger:dagger:2.27"
35
- implementation ' androidx.constraintlayout:constraintlayout:1.1.3'
36
35
kapt " com.google.dagger:dagger-compiler:2.27"
36
+ implementation ' androidx.constraintlayout:constraintlayout:1.1.3'
37
37
implementation project(' :base' )
38
38
testImplementation ' junit:junit:4.12'
39
39
androidTestImplementation ' androidx.test.ext:junit:1.1.1'
Original file line number Diff line number Diff line change
1
+ /build
Original file line number Diff line number Diff line change
1
+ apply plugin : ' com.android.dynamic-feature'
2
+ apply plugin : ' kotlin-android'
3
+ apply plugin : ' kotlin-android-extensions'
4
+ apply plugin : ' kotlin-kapt'
5
+
6
+ android {
7
+ compileSdkVersion 29
8
+
9
+
10
+ defaultConfig {
11
+ minSdkVersion 21
12
+ targetSdkVersion 29
13
+ versionCode 1
14
+ versionName " 1.0"
15
+
16
+ }
17
+
18
+
19
+ }
20
+
21
+ dependencies {
22
+ implementation fileTree(dir : ' libs' , include : [' *.jar' ])
23
+ implementation project(' :app' )
24
+ implementation project(' :base' )
25
+ implementation " com.google.dagger:dagger:2.27"
26
+ kapt " com.google.dagger:dagger-compiler:2.27"
27
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <manifest xmlns : android =" http://schemas.android.com/apk/res/android"
3
+ xmlns : dist =" http://schemas.android.com/apk/distribution"
4
+ package =" com.mindorks.sample.feature.three" >
5
+
6
+ <dist : module
7
+ dist : instant =" false"
8
+ dist : title =" @string/title_feature_three" >
9
+ <dist : delivery >
10
+ <dist : on-demand />
11
+ </dist : delivery >
12
+
13
+ <dist : fusing dist : include =" true" />
14
+ </dist : module >
15
+
16
+ <application >
17
+ <activity android : name =" .FeatureThreeActivity" />
18
+ </application >
19
+
20
+ </manifest >
Original file line number Diff line number Diff line change
1
+ package com.mindorks.sample.feature.three
2
+
3
+ import androidx.appcompat.app.AppCompatActivity
4
+ import android.os.Bundle
5
+ import android.util.Log
6
+ import com.mindorks.dagger.multi.module.base.data.DatabaseService
7
+ import com.mindorks.dagger.multi.module.base.data.NetworkService
8
+ import com.mindorks.dagger.multi.module.base.utils.InjectUtils
9
+ import com.mindorks.sample.feature.three.di.component.DaggerFeatureThreeComponent
10
+ import javax.inject.Inject
11
+
12
+ class FeatureThreeActivity : AppCompatActivity () {
13
+
14
+ @Inject
15
+ lateinit var databaseService: DatabaseService
16
+
17
+ @Inject
18
+ lateinit var networkService: NetworkService
19
+
20
+ override fun onCreate (savedInstanceState : Bundle ? ) {
21
+ super .onCreate(savedInstanceState)
22
+ setContentView(R .layout.activity_feature_three)
23
+
24
+ DaggerFeatureThreeComponent
25
+ .builder()
26
+ .baseComponent(InjectUtils .provideBaseComponent(applicationContext))
27
+ .build()
28
+ .inject(this )
29
+
30
+ Log .d(" DaggerSample_Feature3" , databaseService.toString())
31
+ }
32
+ }
Original file line number Diff line number Diff line change
1
+ package com.mindorks.sample.feature.three.di.component
2
+
3
+ import com.mindorks.dagger.multi.module.base.di.component.BaseComponent
4
+ import com.mindorks.sample.feature.three.FeatureThreeActivity
5
+ import com.mindorks.sample.feature.three.di.module.FeatureThreeModule
6
+ import com.mindorks.sample.feature.three.di.scopes.FeatureThreeScope
7
+ import dagger.Component
8
+
9
+ @FeatureThreeScope
10
+ @Component(
11
+ dependencies = [BaseComponent ::class ],
12
+ modules = [FeatureThreeModule ::class ]
13
+ )
14
+ interface FeatureThreeComponent {
15
+
16
+ fun inject (activity : FeatureThreeActivity )
17
+
18
+ }
Original file line number Diff line number Diff line change
1
+ package com.mindorks.sample.feature.three.di.module
2
+
3
+ import dagger.Module
4
+
5
+ @Module
6
+ class FeatureThreeModule {
7
+ }
Original file line number Diff line number Diff line change
1
+ package com.mindorks.sample.feature.three.di.scopes
2
+
3
+ import javax.inject.Scope
4
+
5
+ @Scope
6
+ @Retention(AnnotationRetention .SOURCE )
7
+ annotation class FeatureThreeScope
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <androidx .constraintlayout.widget.ConstraintLayout xmlns : android =" http://schemas.android.com/apk/res/android"
3
+ xmlns : app =" http://schemas.android.com/apk/res-auto"
4
+ xmlns : tools =" http://schemas.android.com/tools"
5
+ android : layout_width =" match_parent"
6
+ android : layout_height =" match_parent"
7
+ tools : context =" com.mindorks.sample.feature.three.FeatureThreeActivity" >
8
+
9
+ </androidx .constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change @@ -3,3 +3,4 @@ include ':app'
3
3
include ' :base'
4
4
include ' :feature-one'
5
5
include ' :feature-two'
6
+ include ' :featureThree'
You can’t perform that action at this time.
0 commit comments