Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid scoping errors in our Dagger setup #1597

Merged
merged 2 commits into from
Dec 10, 2021
Merged

Conversation

aitorvs
Copy link
Collaborator

@aitorvs aitorvs commented Dec 2, 2021

Task/Issue URL: https://app.asana.com/0/414730916066338/1201415414578549/f

Description

This PR harmonises the way we will scope dependencies in Dagger so that we avoid past mistakes mixing scope annotations resulting in unpexpected behavior.
We have also ditched the ObjectGraph naming and use Scope all over.

Recommended to see the asana task for more information about this.

With this PR we will have the following dagger scopes

  • AppScope -> bound to the life of the application
  • ActivityScope -> should be used for Activities
  • FragmentScope -> should be used for Fragments
  • QuickSettingsScope -> only use the quick tile setting for AppTP
  • ReceiverScope -> should be used for broadcast receivers
  • VpnScope -> only used for Vpn service

Exceptions
We currently do NOT support nesting dagger scopes, this means that the AppScope is the parent of ALL remaining scopes and, ALL remaining scopes are siblings, ie.

  • children scopes have access to the dependencies in the parent scope
  • sibling scopes do not have access to the dependencies in other siblins

Because we don't yet support nesting, some vpn-related activities that SHOULD use the ActivityScope are actually using the VpnScope, all because they need some dependencies that are contributed to the VpnScope.
To track those for future fixes, we have added an annotation dubbed @WrongScope that provide information as to what should be the appropriate scope.
In the future, when nesting is supported, we just need to find usages of that annotation and fix the scope.

Incidentally, and because we are heavy users of multi-bindings and unfortunatelly those require the JvmSuppressWildcards annotations, I have added a sugar over Set and Map multibindings to avoid mistakes.

Steps to test this PR

This PR should not change any behavior, just fixes the usage of dagger annotations. If anything breaks, should now break at build time (this is why the WrongScope annotation exists now)

  • Just perform regular smoke tests for the app and AppTP

@aitorvs
Copy link
Collaborator Author

aitorvs commented Dec 3, 2021

Current dependencies on/for this PR:

This comment was auto-generated by Graphite and will continue to be automatically updated while this PR remains open.

@aitorvs aitorvs force-pushed the feature/aitor/singlein branch 5 times, most recently from 85bea57 to de9c77e Compare December 8, 2021 18:52
@CDRussell CDRussell removed their assignment Dec 9, 2021
@CDRussell
Copy link
Member

Sorry @aitorvs, I've been struggling to get time to review this. Can you either find another reviewer or tolerate waiting until next week for a review?

@aitorvs aitorvs force-pushed the feature/aitor/singlein branch from de9c77e to bb87d74 Compare December 9, 2021 10:51
@marcosholgado marcosholgado self-assigned this Dec 9, 2021
Copy link
Contributor

@marcosholgado marcosholgado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! Everything working as expected 👍

@aitorvs aitorvs force-pushed the feature/aitor/singlein branch from bb87d74 to 2a4520a Compare December 10, 2021 08:19
@aitorvs aitorvs merged commit ae6bd28 into develop Dec 10, 2021
@aitorvs aitorvs deleted the feature/aitor/singlein branch December 10, 2021 08:53
aitorvs added a commit that referenced this pull request Dec 13, 2021
…#1604)

Task/Issue URL: https://app.asana.com/0/414730916066338/1201432423603230/f

### Description
In PR #1597 we're harmonising the way we name dagger components and how we contribute dependencies to them. As a recap:
* Use @SingletonIn(AppScope::class) for app scope
* Use @SingletonIn(ActivityScope::class) for activity scope
* Use @SingletonIn(FragmentScope::class) for fragment scope


This a follow up PR to enable nesting those scopes:
* AppScope -> ActivityScope -> FragmentScope

Nesting means:
* child scopes can get access to dependencies in their parent scopes (but not the other way around), ie.
* `FragmentScope` would get access to deps in Fragment, Activity and App scopes
* `ActivityScope` would get access to deps in Activity and App scopes
* `AppScope` would get access to deps in App scope


The PR changes the fragments that were not in the `FragmentScope` to use that one instead. Functionality should not be affected at all

### Steps to test this PR
Smoke tests for app and AppTP
CDRussell pushed a commit that referenced this pull request Dec 15, 2021
Task/Issue URL: https://app.asana.com/0/414730916066338/1201415414578549/f

### Description
This PR harmonises the way we will scope dependencies in Dagger so that we avoid past mistakes mixing scope annotations resulting in unpexpected behavior.
We have also ditched the `ObjectGraph` naming and use `Scope` all over.

Recommended to see the [asana task](https://app.asana.com/0/414730916066338/1201415414578549/f) for more information about this.


With this PR we will have the following dagger scopes
* `AppScope` -> bound to the life of the application
* `ActivityScope` -> should be used for Activities
* `FragmentScope` -> should be used for Fragments
* `QuickSettingsScope` -> only use the quick tile setting for AppTP
* `ReceiverScope` -> should be used for broadcast receivers
* `VpnScope` -> only used for Vpn service


_Exceptions_
We currently do NOT support nesting dagger scopes, this means that the `AppScope` is the parent of ALL remaining scopes and, ALL remaining scopes are siblings, ie.
* children scopes have access to the dependencies in the parent scope
* sibling scopes do not have access to the dependencies in other siblins

Because we don't yet support nesting, some vpn-related activities that SHOULD use the `ActivityScope` are actually using the `VpnScope`, all because they need some dependencies that are contributed to the `VpnScope`.
To track those for future fixes, we have added an annotation dubbed `@WrongScope` that provide information as to what should be the appropriate scope.
In the future, when nesting is supported, we just need to find usages of that annotation and fix the scope.

Incidentally, and because we are heavy users of multi-bindings and unfortunatelly those require the `JvmSuppressWildcards` annotations, I have added a sugar over `Set` and `Map` multibindings to avoid mistakes.

### Steps to test this PR
This PR should not change any behavior, just fixes the usage of dagger annotations. If anything breaks, should now break at build time (this is why the `WrongScope` annotation exists now)

* Just perform regular smoke tests for the app and AppTP
CDRussell pushed a commit that referenced this pull request Dec 15, 2021
…#1604)

Task/Issue URL: https://app.asana.com/0/414730916066338/1201432423603230/f

### Description
In PR #1597 we're harmonising the way we name dagger components and how we contribute dependencies to them. As a recap:
* Use @SingletonIn(AppScope::class) for app scope
* Use @SingletonIn(ActivityScope::class) for activity scope
* Use @SingletonIn(FragmentScope::class) for fragment scope


This a follow up PR to enable nesting those scopes:
* AppScope -> ActivityScope -> FragmentScope

Nesting means:
* child scopes can get access to dependencies in their parent scopes (but not the other way around), ie.
* `FragmentScope` would get access to deps in Fragment, Activity and App scopes
* `ActivityScope` would get access to deps in Activity and App scopes
* `AppScope` would get access to deps in App scope


The PR changes the fragments that were not in the `FragmentScope` to use that one instead. Functionality should not be affected at all

### Steps to test this PR
Smoke tests for app and AppTP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants