Dagger Components

Purpose

Dagger Components define the bridge between dependency providers (modules) and the consumers (activities, classes) in this media player project. They specifically scope and inject instances such as the FSM player, state factories, controllers, and monitors into activities that handle media playback. This approach ensures modularity, testability, and clear lifecycle management of dependencies.

Within the broader Dependency Injection Setup, Dagger Components uniquely focus on *declaring injection targets* and *exposing scoped dependencies* like the `StateFactory` for FSM state creation, which is not covered by modules alone.

Functionality

Dagger Components operate as the configured injection containers that:

Two primary components reflect different configurations for injection targets and modules:

FsmComonent (for DoubleViewTubiPlayerActivity)

Key snippet:

@ActicityScope
@Component(modules = PlayerModuleDefault.class)
public interface FsmComonent {
    StateFactory getStateFactory();
    void inject(DoubleViewTubiPlayerActivity activity);
}

FsmComonentReal (for RealActivity)

Key snippet:

@ActicityScope
@Component(modules = FSMModuleReal.class)
public interface FsmComonentReal {
    void inject(RealActivity activity);
}

Integration with Dependency Injection Setup

Dagger Components work hand-in-hand with Dagger Modules and custom scopes:

Components complement modules by:

This separation enhances modularity by decoupling *how* dependencies are created (modules) from *where* they are injected (components).

Relationship to Other Subtopics

By clearly defining injection boundaries, components enable seamless FSM player lifecycle management and UI integration.


Diagram: Dagger Component Injection Flow

flowchart TD
    ModuleDefault[PlayerModuleDefault\n(provides FSM Player,\nStateFactory, Controllers)]
    ModuleReal[FSMModuleReal\n(provides FSM Player,\nad retrievers, monitors)]

    FsmComponent[FsmComonent\n@ActivityScope]
    FsmComponentReal[FsmComonentReal\n@ActivityScope]

    DoubleViewActivity[DoubleViewTubiPlayerActivity]
    RealActivity[RealActivity]

    ModuleDefault --> FsmComponent
    ModuleReal --> FsmComponentReal

    FsmComponent -->|inject| DoubleViewActivity
    FsmComponentReal -->|inject| RealActivity

    FsmComponent -->|exposes| StateFactory[StateFactory]

    style ModuleDefault fill:#d9f0ff,stroke:#blue,stroke-width:1px
    style ModuleReal fill:#ffe0e0,stroke:#d00,stroke-width:1px
    style FsmComponent fill:#e0ffe0,stroke:#080,stroke-width:1px
    style FsmComponentReal fill:#fff0b3,stroke:#aa0,stroke-width:1px

This design ensures activities receive properly scoped FSM player instances and supporting objects, promoting clean separation of concerns in dependency management.