-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Resolving dependency marked with @Named ? #401
Comments
As stated in javadocs, this method throws:
As I understand, your SomePresenter is not an injectible type, instead being provided in two named flavours in a module. Correct me if I'm wrong - but it seems that dagger won't let You do that. |
Thanks for the quick response. Yes, SomePresenter is being provided by my module. |
You basically have two options (which are not dagger-specific):
@Inject @Named("1") Provider<SomePresenter> presenter1Provider;
@Inject @Named("2") Provider<SomePresenter> presenter2Provider;
public void someMethod() {
SomePresenter presenter = /* use presenter1Provider or presenter2Provider */.get();
}
|
I would suggest a slight alteration of Thomas' option-1 code to: class PresenterEntryPoint {
@Inject @Named("1") Lazy<SomePresenter> presenter1;
@Inject @Named("2") Lazy<SomePresenter> presenter2;
} ... but it's basically the same approach. Dagger 1.0 is definitely |
Thanks for the great answers. I took the provider approach. |
Also stop distinguishing between explicit bindings and delegate declarations during resolution time; it's confusing and unnecessary. Github: Fixes square#401 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=127997438
I have a class called SomePresenter.
I provide two instances of this class one @nAmed("1") and other @nAmed("2")
In the code I need to resolve this dependency depending on some data and logic, therefore I can't do property injection or constructor injection.
The text was updated successfully, but these errors were encountered: