uber / uber/RIBs

[Android] Constructor injection for Interactors is disallowed

Open
#343 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Android
Dominant language
Kotlin
Stars
7.9k
Forks
914
PR merge metrics
No merged PRs in 30d

Description

After completing tutorial 2, I attempted to improve the Dagger usage by using constructor injection where possible. I succeeded in making RootRouter, LoggedOutBuilder, and LoggedOutRouter constructor injected and was able to remove a few manually-written @Provides methods as a result.

Next, I wanted to convert RootInteractor to use constructor injection. This would allow me to remove its manual creation from RootBuilder and make its presenter member private and final. But it appears that several features in the tooling prevent me from trying this:

  • First, it's explicitly disallowed by InteractorAnnotationVerifier: "Interactor cannot have custom constructors - all dependencies and setup should happen in the builder of $type"
  • If I disable that check, I get compilation errors because the generated Test*Interactor expects a no-arg constructor. It looks like I could maybe rewrite InteractorTestGenerator to be more flexible, but then I'd be getting pretty deep into the tools without knowing the framework that well.

So: Why is constructor injection of interactors disallowed?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading InteractorAnnotationVerifier and InteractorTestGenerator, then inspect RootInteractor and RootBuilder as described in the issue. Determine why custom constructors are rejected and how generated Test*Interactor depends on a no-argument constructor; done means documenting the constraint or defining the required tooling changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.