dagger

Dagger 2.11 - A binding with matching key exists in component

China☆狼群 提交于 2019-11-30 05:45:31
问题 I have a small scenario where I have this following structure where I'm trying to inject fragment manager in baseActivity Fragment but for some reason I'm running out of luck :( @Singleton @Component(modules = { AppModule.class, ActivityModule.class, AndroidSupportInjectionModule.class }) public interface AppComponent extends AndroidInjector<App> { @Override void inject(App application); @Component.Builder interface Builder { @BindsInstance AppComponent.Builder application(App application);

Context cannot be provided without an @Provides-annotated method, but it is?

佐手、 提交于 2019-11-30 01:34:32
问题 I have the following simple module: @Module public class ApplicationModule { private CustomApplication customApplication; public ApplicationModule(CustomApplication customApplication) { this.customApplication = customApplication; } @Provides @Singleton CustomApplication provideCustomApplication() { return this.customApplication; } @Provides @Singleton @ForApplication Context provideApplicationContext() { return this.customApplication; } } And the respective simple component: @Singleton

Dagger + Retrofit. Adding auth headers at runtime

不羁岁月 提交于 2019-11-29 20:28:09
I'm wondering if there is a way for Dagger to know that it should recreate an object when new data is available. The instance I am speaking of is with the request headers I have for retrofit. At some point (when the user logs in) I get a token that I need to add to the headers of retrofit to make authenticated requests. The issue is, I'm left with the same unauthenticated version of retrofit. Here's my injection code: @Provides @Singleton OkHttpClient provideOkHttpClient(Cache cache) { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel

Dagger 2 examples [closed]

扶醉桌前 提交于 2019-11-29 19:49:15
Dagger 2 is around the corner but the available examples wouldn't even compile right off the box, and the documentation is a copy-paste-replace from Dagger 1. Does anyone have an example of a proper application working on Google's Dagger 2? I've just published sample app based on Gradle which integrates Dagger2, retrolambda, butterknife and lombok. You can find it here: https://github.com/mgrzechocinski/dagger2-example . Hope it would help :) I've just ported u2020-mvp app to Dagger 2. We use it as our sandbox app. Dagger 2 has nice implementation of scopes by the way. Components are really

Dagger 2 error: dependency “cannot be provided without an @Inject constructor” while it actually annotated with @Inject

六月ゝ 毕业季﹏ 提交于 2019-11-29 10:34:07
问题 I've started using Dagger 2 and faced strange issue that looks like a bug to me. I have 3 modules, that are composed into one subcomponent, which in turn extends/pluses higher level component. Subcomponent is pretty simple: just combination of modules and a single injection point: @Singleton @Subcomponent( modules = { NavigationDrawerModule.class, NavigationListModule.class, SwitcherModule.class } ) public interface NavigationDrawerComponent { NavigationDrawerFragment inject

Cannot create an instance of custom ViewModel

℡╲_俬逩灬. 提交于 2019-11-29 09:18:19
I am using dagger2 library. whenever I am trying to run my project is says not able to create instance of view model class. main activity where I am trying to create an instance ((MovieApplication) getApplication()).getAppComponent().inject(this); mViewModel = ViewModelProviders.of(this).get(MoviesDataViewModel.class); My factory class public class ViewModelFactory implements ViewModelProvider.Factory { private MoviesDataViewModel mViewModel; @Inject public ViewModelFactory(MoviesDataViewModel viewModel) { this.mViewModel = viewModel; } @Override public <T extends ViewModel> T create(Class<T>

How to migrate missing inject from module with complete = false from Dagger 1 to Dagger 2

断了今生、忘了曾经 提交于 2019-11-29 08:16:48
I have a library project/module that is used by both Android apps and regular java apps. In Dagger 1 this project/module has property complete = false . Within there is an @Inject field that is not satisfied by any class implementation or @Provides method. The idea is to force the "top" module(s) which has complete = true to provide system specific implementation Just for the sake of example: In the library project I have ActLogin activity that have field @Inject @Named("app version") mAppVersion . The value of this field is used when logging in into a server. ActLogin is used by several apps

Dagger: IllegalArgumentException: No injector factory bound for Class

两盒软妹~` 提交于 2019-11-29 05:24:27
I am new to Dagger 2. I have 2 Activities, I want to use injected ViewModel for both. Here is my ViewModuleFactory : @Singleton public class ProductViewModelFactory implements ViewModelProvider.Factory { private final Map<Class<? extends ViewModel>, Provider<ViewModel>> creators; @Inject public ProductViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) { this.creators = creators; } @SuppressWarnings("unchecked") @Override public <T extends ViewModel> T create(Class<T> modelClass) { Provider<? extends ViewModel> creator = creators.get(modelClass); if (creator == null

Dagger can't find injectable members on a module

和自甴很熟 提交于 2019-11-29 04:09:45
问题 I'm using Dagger for dependency injection in an Android project, and can compile and build the app fine. The object graph appears to be correct and working, but when I add dagger-compiler as a dependency to get errors at compile time, it reports some bizarre errors: [ERROR] error: No binding for com.squareup.tape.TaskQueue<com.atami \ .mgodroid.io.NodeIndexTask> required by com.atami \ .mgodroid.ui.NodeIndexListFragment for com.atami.mgodroid \ .modules.OttoModule [ERROR] error: No binding

单体密度矩阵、粒子密度

故事扮演 提交于 2019-11-29 03:16:00
有待修正。。。 对于全同多粒子态,有密度算符 \(\rho_N\) ,现在要对其约化,求出单体的约化密度算符。由于全同粒子中,各个粒子地位相同,所以 \(N\) 粒子的约化单体密度算符为 \[ \rho=N\text{tr}_{2,3,\cdots,N}(\rho_N) \] 其中系数 \(N\) 是因为有 \(N\) 个全同的粒子。求trace就是选取一组完备基矢量,作用在 \(\rho\) 两边,然后对所要约化的粒子积分(求和)。为求trace,取一个多粒子的对称化基矢组 \(|b_1,b_2,\cdots,b_N\rangle\) ,它是完备的,表示 \(N\) 个粒子处于一共这 \(N\) 个态上。于是有 \[ \rho(b,b')=N\int\cdots\int\text{d}b_2\text{d}b_3\cdots\text{d}b_N\langle b,b_2,\cdots,b_N|\rho_N| b',b_2,\cdots,b_N\rangle \] 上面对粒子 \(2,3,\cdots,N\) 积分,而对第一个粒子保留不作积分。由于选取的是对称化基矢量,所以上式左边不能写成 \(\langle b|\rho|b'\rangle\) ,而只能写为 \(\rho(b,b')\) . 这就是单体密度矩阵(因为它一般不写成算符的形式,只写成矩阵元的形式