Skip to main content

Module context

Expand description

Execution Context

This module provides the ExecutionContext wrapper around the Container for dependency injection in command handlers. It offers a clean interface for accessing services needed during command execution.

§Purpose

The ExecutionContext serves as an abstraction layer between the Container (which holds raw services) and command handlers (which need typed access). This separation provides:

  • Clean Interface: Command handlers get strongly-typed service access
  • Thread Safety: All services are properly wrapped for concurrent access
  • Future-Proofing: Easy to add new services without changing handler signatures
  • Testing Support: Easy to inject test doubles through Container

§Design

Container (bootstrap) → ExecutionContext (dispatch) → Command Handlers

Raw services        Clean typed access      Business logic

§Usage Example

use torrust_tracker_deployer_lib::bootstrap::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
use torrust_tracker_deployer_lib::presentation::cli::dispatch::ExecutionContext;
use std::sync::Arc;
use std::path::Path;

// Create execution context from container
let container = Container::new(VerbosityLevel::Normal, Path::new("."));
let context = ExecutionContext::new(Arc::new(container), global_args);

// Command handlers access services through context
let user_output = context.user_output();
user_output.lock().borrow_mut().progress("Processing...");

Structs§

ExecutionContext
Design Consideration: Shared State Access