Skip to content

Overhaul core Tracker: extract IoC Container #1187

@josecelano

Description

@josecelano

Parent issue: #1181

I'm working on a big refactor. I'm extracting responsibilities from the core tracker. The Tracker is acting like a kind of IoC container because it instantiates many services. Since I'm extracting those services from the tracker we need a container for them. I'm going to add a IoC container so this code:

#[tokio::main]
async fn main() {
    let (config, tracker, udp_ban_service, stats_event_sender, stats_repository) = bootstrap::app::setup();

    let jobs = app::start(&config, tracker, udp_ban_service, stats_event_sender, stats_repository).await;

    // handle the signals
    tokio::select! {
        _ = tokio::signal::ctrl_c() => {
            tracing::info!("Torrust shutting down ...");

            // Await for all jobs to shutdown
            futures::future::join_all(jobs).await;
            tracing::info!("Torrust successfully shutdown.");
        }
    }
}

can be replaced with something like:

#[tokio::main]
async fn main() {
    let app_container: AppContanier = bootstrap::app::setup();

    let jobs = app::start(&config, app_container).await;

    // handle the signals
    tokio::select! {
        _ = tokio::signal::ctrl_c() => {
            tracing::info!("Torrust shutting down ...");

            // Await for all jobs to shutdown
            futures::future::join_all(jobs).await;
            tracing::info!("Torrust successfully shutdown.");
        }
    }
}

In the Index we called AppData but I think I will call it AppContainer.

There is a crate shaku to handle compilation time dependencies but I don't want to introduce complex dependencies for now. And some dependencies are defined at runtime (database, ..).

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions