Closed ultraon closed 7 years ago
Please ask this on Stack Overflow, not on the issue tracker.
Sorry, but i think it's a bug, because i didn't find any reason in current Dagger2 doc. May be you can confirm fact of bug or not? (then if no - i'll ask my question on the Stack Overflow)
It's not a bug. Component hierarchies that mix scopes in this way are not supported.
Thank you, i hope i'll get more details about it. I asked question here: https://stackoverflow.com/questions/44157859/component-which-dependent-from-other-components-with-different-scopes-component
@ultraon I'm trying to implement the same setup using multi-layer android project and dagger 2.15. Can you please point me to how you have solved this problem? please consider that i want to abstract each layer and only expose the interfaces used to talk to other layers. Thanks in advance.
@andromedcodes I solved this issue by extending ServiceComponent with BlComponent and PresentationComponent with ServiceComponent. But it is a hack and I don't like it. BTW PresentationScope can include others components as dependencies but only one from this components can has a scope. It is very strange for me.
I agree with @ultraon. What is the motivation behind the decision to allow having only one scoped component's dependency? The answer on SO explains nothing. As @ultraon mentioned on SO if component's dependencies don't expose the same types everything should be fine. In any case you can't know that the type provided by provision method is scoped or not (or distinguish its scope).
In my case I've used interfaces only with provision methods extracted from my components as dependencies, which hides the actual components and their scopes. After @guliash showed me this issue, I began to worry that by hiding components (and scopes) behind interfaces, I was using a bug in validation and as soon as it was fixed by forbidding usage of interfaces not marked by @Component
annotation as component's dependencies, all my architecture would block me from updating dagger in project. @ronshapiro, is using interfaces without @Component
annotation as dependencies of components a valid approach or is it a bug that would be fixed in future?
In the #1225 @ronshapiro confirmed usage of interfaces without @Component
annotation as dependencies as valid approach.
Hello, i have complex multi-tier architecture in my Android project.
Currently i want to use the following structure of the DI components and modules:
To build the main graph i use the following code:
In the PresentationLayer i use only "presentationComponent" to provide required dependencies from ServiceComponent/Layer and BLComponent/Layer.
Currently scenario above doesn't work, because PresentationComponent depends on the 2 scoped components with the error "...depends on more than one scoped component:...". Though it allows to use one scoped component with many non-scoped components. This architecture is directed to restrict to use internal layer entities on the upper layers and in the same time to have independent tests (unit & instrumentation) on each layer/module.
Could anybody help me to understand is it bug or desirable behavior of the Dagger processor? (and why?)