-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ab02f5
commit c39f76d
Showing
24 changed files
with
731 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
base/src/main/java/com/heyongrui/base/dagger/AppComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.heyongrui.base.dagger; | ||
|
||
|
||
import com.heyongrui.base.assist.AppData; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import dagger.Component; | ||
|
||
/** | ||
* 2019/8/26 | ||
* lambert | ||
*/ | ||
|
||
@Singleton | ||
@Component(modules = {AppModule.class}) | ||
public interface AppComponent { | ||
/* | ||
* 暴露给依赖者Component(依赖者若使用@Component,此处必须暴露,否则依赖者无法@Inject AppData;依赖者若使用@Subcomponent,此处可以不暴露依赖者也可@Inject AppData) | ||
*/ | ||
AppData appData(); | ||
} |
40 changes: 40 additions & 0 deletions
40
base/src/main/java/com/heyongrui/base/dagger/AppModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.heyongrui.base.dagger; | ||
|
||
|
||
import com.heyongrui.base.app.BaseApplication; | ||
import com.heyongrui.base.assist.AppData; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
|
||
/** | ||
* 2019/8/26 | ||
* lambert | ||
*/ | ||
|
||
@Module | ||
public class AppModule { | ||
private BaseApplication baseApplication; | ||
|
||
public AppModule(BaseApplication baseApplication) { | ||
this.baseApplication = baseApplication; | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
BaseApplication providesApplication() { | ||
return baseApplication; | ||
} | ||
|
||
|
||
/* | ||
* @Inject AppData使用单例,由于AppModule在BaseApplication中初始,所以@Inject AppData是全局单例(而且AppComponent也必须加上@Singleton) | ||
*/ | ||
@Provides | ||
@Singleton | ||
AppData provideAppData() { | ||
return new AppData(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
base/src/main/java/com/heyongrui/base/dagger/PerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.heyongrui.base.dagger; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import javax.inject.Scope; | ||
|
||
/** | ||
* 2019/8/26 | ||
* lambert | ||
*/ | ||
@Documented | ||
@Scope | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface PerActivity { | ||
} |
Oops, something went wrong.