android使用inject需要注意的地方
1.viewmodel里面添加注解
@Inject
FavoritesDBManager mFavoritesDBManager;
2.Component里面添加dependencies = AppComponent.class
@Component(modules = CoinSearchModule.class,dependencies = AppComponent.class)
3.activity里面添加.appComponent(ComponentHolder.getComponent())
@Override
protected void inject() {
ARouter.getInstance().inject(this);
CoinDetailComponent component = DaggerCoinDetailComponent.builder()
.coinDetailModule(new CoinDetailModule(this))
.appComponent(ComponentHolder.getComponent())
.build();
component.injectActivity(this);
component.injectViewModel(mViewModel);
mBinding.setActivity(this);
mBinding.setViewmodel(mViewModel);