question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sub component implementation inconsistent between different parent components in regards to scopes.

See original GitHub issue

Version 2.7, & 2.8 Consumption is in a large android project, the issue only manifests itself in my androidTest src set component.

Component and scope layout is: AppComponent/ActivityComponent/ViewComponent where App component is @Singleton the activity component has a custom scope, and the view component has a custom scope.

Inside of my androidTest src set I create a ActivityTestComponent that is @Singleton and includes the ActivityComponent as a sub component. This allows me replace the majority of my object graph with mocks and give the activity the test component version of its component in its test run.

Problem that is occurring is the ViewComponent generated as a sub class of the test component is not correctly wrapping the objects provided in the double check provider.

AppCompImpl.java.txt TestCompImpl.java.txt

I’ve tried to replicate in a small sample project but the trivial version of this component layout has not produced the issue.

ActivityComponent is added as a sub component of the AppComponent via the @Module(subcomponent) and a @Binds @IntoMap @ClassKey on the component builder type. ActivityComponent is added as a sub component of the ActivityTestComponent via a method directly exposing the ActivityComponent.Builder on ActivityTestComponent.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
gk5885commented, Jan 6, 2017

@trevjonez, the problem is two-fold:

  1. Nothing about your scope is Dagger-specific. The Dagger processor only runs on Dagger types and @Scope is part of JSR 330, not Dagger.
  2. If Dagger were to validate things like @Scope annotations, it would have had to have run on that class in order to have caught the error (because source retention wouldn’t have been retained in the class file).

That creates a semi-awkward situation in which you would potentially run the Dagger processor on build targets that contain no Dagger types just to get the extra static analysis. If you’re going to commit to running static analysis in the first place, Error Prone is the better choice because it will give you more complete analysis and suggested fixes.

0reactions
tbroyercommented, Jan 6, 2017

That creates a semi-awkward situation in which you would potentially run the Dagger processor on build targets that contain no Dagger types just to get the extra static analysis.

Well, you sort-of have to do it already, for classes with @Inject, if you don’t want the message telling you to “run Dagger on that class”. Not for static analysis only, but still.

That said, I agree that it’s not Dagger’s role to check the retention of scope annotations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why subcomponent can't have the same scope as its parent ...
1 Answer 1 ... The parent component will be created first, then the subcomponent. So the subcomponent lifetime starts "after" the lifetime of...
Read more >
Nested components cannot access external data #49 - GitHub
I was having a go with alpinejs and I noticed that, when there are nested components, the internal component cannot access the scope...
Read more >
Subcomponents - Dagger
Subcomponents are components that inherit and extend the object graph of a parent component. You can use them to partition your application's object...
Read more >
Dagger 2. Part II. Custom scopes, Component dependencies ...
Here we're gonna talk custom scopes, components linking via component dependencies and ... Subcomponent has access to all parents objects.
Read more >
Part 12 - Acquisition of Commercial Products and Commercial ...
12.000 Scope of part.​​ It implements the Federal Government's preference for the acquisition of commercial products and commercial services ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found