相关系列文章react
模块化解耦框架RxFluxArchitecture1-框架简介android
模块化解耦框架RxFluxArchitecture2-基本功能实现git
模块化解耦框架RxFluxArchitecture3-订阅管理绑定生命周期github
模块化解耦框架RxFluxArchitecture4-依赖库与依赖注入编程
模块化解耦框架RxFluxArchitecture5-Application多模块共存json
框架中使用 Dagger.Android 实现依赖注入功能。缓存
core-arch-annotations
core-arch-annotations
是注解库,配合注解编译库core-arch-processor
使用,实现 Application 多模块共存。bash
core-eventbus
core-eventbus
在 EventBus 基础上添加 Tag 功能,配合注解编译库core-eventbus-processor
使用,提升效率。cookie
core-arch
core-arch-annotations
、core-eventbus
。RxSubscriberView
实现该接口的 View,RxFlux
根据其生命周期自动注册订阅、取消订阅,接收core-eventbus
发送的通知。RxFluxView<T extends ViewModel>
实现该接口的 View,可获取对应的 Store 并关联 View 的生命周期。RxAppLifecycle
Application 生命周期代理接口。RxApp
继承DaggerApplication
,为使用@ContributesAndroidInjector
注解的 Activity 自动生成依赖注入器。使用反射获取编译生成类RxAppLifecycleImpl
,实现 Application 多模块共存。RxFlux
管理 View 生命周期,关联 View 与 Store,使用@Inject
标注构造方法注入。RxDispatcher
使用core-eventbus
对 View 和 Store 注册订阅、发送通知、取消订阅,使用@Inject
标注构造方法注入。RxActionManager
管理RxAction
与io.reactivex.disposables.Disposable
对应关系,使用@Inject
标注构造方法注入。RxStoreFactory
实现ViewModelProvider.Factory
,为 View 提供 Store,使用@Inject
标注构造方法注入。RxActionCreator
全部 ActionCreator 的父类,封装RxDispatcher
和RxActionManager
,为子类提供公共方法。RxFluxModule
全局依赖注入仓库,提供ViewModelProvider.Factory
的实现类RxStoreFactory
实例对象,提供Context
的子类Application
实例对象。RxFluxActivity<T>
、RxFluxFragment<T>
、RxFluxDialog<T>
实现RxFluxView<T>
、RxSubscriberView
接口方法,是全部 View 的父类。RxFluxActivity<T>
实现dagger.android.supportHasSupportFragmentInjector
接口,为使用@ContributesAndroidInjector
注解的 Fragment 自动生成依赖注入器。core-common
封装自定义父类和自定义经常使用工具方法,添加通用依赖,使用时可按本身编程习惯从新编写。app
core-arch
,惟一不可变更,其他依赖均可替换。core-image
、core-utils
、core-progress
、core-cookie
。base
BaseApp
继承RxApp
,全局使用的Application,初始化全局使用的方法工具。BaseView
自定义 View 接口。BaseActivity<T>
实现BaseView
,继承RxFluxActivity<T>
,使用ButterKnife,自定义全局响应RxLoading
、RxError
、RxRetry
。BaseFragment<T>
实现BaseView
,继承RxFluxFragment<T>
,使用ButterKnife,自定义ToolBar
、Menu
。BaseDialog<T>
实现BaseView
,继承RxFluxDialog<T>
,使用ButterKnife。common
CommonActionCreator
可全局使用的 ActionCreator,使用@Inject
标注构造方法注入。CommonLoadingDialog
可全局使用的进度弹框,使用@Inject
标注构造方法注入。CommonHttpInterceptor
可全局使用的OkHttp拦截器,使用@Inject
标注构造方法注入。CommonException
自定义异常。CommonModule
通用全局依赖注入仓库,依赖RxFluxModule
。CommonUtils
经常使用自定义工具。CommonLoadMoreView
自定义BaseRecyclerViewAdapterHelper加载样式。core-image
core-image
封装Glide,解析图片。
core-utils
ActivityUtils
自定义 Activity 中经常使用方法。LocalStorageUtils
封装Fastjson的工具类,使用@Inject
标注构造方法注入。core-progress
core-progress
使用OkHttp、Retrofit,依赖核心库core-arch
,完成下载进度提醒,使用@Inject
标注构造方法注入。
core-cookie
core-cookie
接口认证使用 Cookie 缓存,使用@Inject
标注构造方法注入。
壳模块module-app
中SimpleApplication
继承BaseApp
,使用依赖注入器SimpleComponent
,实现依赖注入。
@RxAppBody
public class SimpleApplication extends BaseApp {
@Override
protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
return DaggerSimpleComponent.builder().application(this).build();
}
}
复制代码
SimpleComponent
中添加业务模块依赖注入仓库、通用全局依赖注入仓库CommonModule
、Dagger.Android支持仓库AndroidSupportInjectionModule
。
@Singleton
@Component(modules = {
GanAppModule.class,
WanAppModule.class,
com.huyingbao.module.wan.kotlin.module.WanAppModule.class,
CommonModule.class,
AndroidSupportInjectionModule.class})
public interface SimpleComponent extends AndroidInjector<SimpleApplication> {
@Component.Builder
interface Builder {
@BindsInstance
SimpleComponent.Builder application(Application application);
SimpleComponent build();
}
}
复制代码
业务模块module-wan
依赖注入仓库WanAppModule
,包含WanInjectActivityModule
和WanStoreModule
。
WanInjectActivityModule
经过注解@ContributesAndroidInjector
,自动生成 Activity 的依赖注入器。WanStoreModule
提供 Store 对象 组成的Map<Class<? extends ViewModel>, Provider<ViewModel>>
,做为RxStoreFactory
的构造方法入参,Store 使用@Inject
标注构造方法注入。每一个 Activity 的注入器中添加WanInjectFragmentModule
,WanInjectFragmentModule
经过注解@ContributesAndroidInjector
,自动生成 Fragment 的依赖注入器。
@Module
public abstract class WanInjectActivityModule {
@ActivityScope
@ContributesAndroidInjector(modules = WanInjectFragmentModule.class)
abstract ArticleActivity injectArticleActivity();
@ActivityScope
@ContributesAndroidInjector(modules = WanInjectFragmentModule.class)
abstract LoginActivity injectLoginActivity();
}
复制代码
开源模块化解耦框架RxFluxArchitecture,欢迎你们点赞Fork,更欢迎点评指导。