pub struct Container { /* private fields */ }Expand description
Application service container
Holds shared services initialized during application bootstrap.
Services are wrapped in Arc<T> for thread-safe shared ownership
across the application.
§Example
use std::path::Path;
use torrust_tracker_deployer_lib::bootstrap::container::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
let working_dir = Path::new(".");
let container = Container::new(VerbosityLevel::Normal, working_dir);
let user_output = container.user_output();
user_output.lock().borrow_mut().success("Operation completed");Implementations§
Source§impl Container
impl Container
Sourcepub fn new(verbosity_level: VerbosityLevel, working_dir: &Path) -> Self
pub fn new(verbosity_level: VerbosityLevel, working_dir: &Path) -> Self
Create a new container with initialized services
Initializes all services with specified verbosity level and working directory:
UserOutputwith providedverbosity_levelFileRepositoryFactorywithDEFAULT_LOCK_TIMEOUTEnvironmentRepositoryusingworking_dir/dataas base directorySystemClockfor time operations
§Arguments
verbosity_level- Controls how verbose the user output will beworking_dir- Base working directory for the application (repository usesworking_dir/data)
§Examples
use std::path::Path;
use torrust_tracker_deployer_lib::bootstrap::container::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
// For normal application use
let container = Container::new(VerbosityLevel::Normal, Path::new("."));
// For completely silent testing
let container = Container::new(VerbosityLevel::Silent, Path::new("/tmp/test"));Sourcepub fn user_output(&self) -> Arc<ReentrantMutex<RefCell<UserOutput>>> ⓘ
pub fn user_output(&self) -> Arc<ReentrantMutex<RefCell<UserOutput>>> ⓘ
Get shared reference to user output service
Returns an Arc<ReentrantMutex<RefCell<UserOutput>>> that can be safely cloned and shared
across threads and function calls. Use the reentrant lock to acquire access, then borrow_mut()
to get mutable access to the user output. The reentrant mutex prevents deadlocks when the
same thread needs to acquire the lock multiple times.
§Example
use std::path::Path;
use torrust_tracker_deployer_lib::bootstrap::container::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
let container = Container::new(VerbosityLevel::Normal, Path::new("."));
let user_output = container.user_output();
user_output.lock().borrow_mut().success("Operation completed");Sourcepub fn file_repository_factory(&self) -> Arc<FileRepositoryFactory> ⓘ
pub fn file_repository_factory(&self) -> Arc<FileRepositoryFactory> ⓘ
Get shared reference to repository factory service
Returns an Arc<FileRepositoryFactory> that can be cheaply cloned and shared
across threads and function calls.
§Example
use std::path::Path;
use torrust_tracker_deployer_lib::bootstrap::container::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
let container = Container::new(VerbosityLevel::Normal, Path::new("."));
let file_repository_factory = container.file_repository_factory();
// Use file_repository_factory to create repositoriesSourcepub fn repository_provider(&self) -> Arc<dyn RepositoryProvider> ⓘ
pub fn repository_provider(&self) -> Arc<dyn RepositoryProvider> ⓘ
Get shared reference to repository provider
Returns an Arc<dyn RepositoryProvider> that can be passed to application-layer
handlers without exposing the concrete infrastructure type.
Sourcepub fn repository(&self) -> Arc<dyn EnvironmentRepository + Send + Sync> ⓘ
pub fn repository(&self) -> Arc<dyn EnvironmentRepository + Send + Sync> ⓘ
Get shared reference to environment repository
Returns an Arc<dyn EnvironmentRepository> that can be cheaply cloned and shared
across threads and function calls. The repository is initialized with the
application’s base data directory during container creation.
§Example
use std::path::Path;
use torrust_tracker_deployer_lib::bootstrap::container::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
let container = Container::new(VerbosityLevel::Normal, Path::new("."));
let repository = container.repository();
// Use repository to load/save environment stateSourcepub fn clock(&self) -> Arc<dyn Clock> ⓘ
pub fn clock(&self) -> Arc<dyn Clock> ⓘ
Get shared reference to clock service
Returns an Arc<dyn Clock> that can be cheaply cloned and shared
across threads and function calls.
§Example
use std::path::Path;
use torrust_tracker_deployer_lib::bootstrap::container::Container;
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
let container = Container::new(VerbosityLevel::Normal, Path::new("."));
let clock = container.clock();
// Use clock for time operationsSourcepub fn create_environment_controller(
&self,
) -> CreateEnvironmentCommandController
pub fn create_environment_controller( &self, ) -> CreateEnvironmentCommandController
Create a new CreateEnvironmentCommandController
Sourcepub fn create_template_controller(&self) -> CreateTemplateCommandController
pub fn create_template_controller(&self) -> CreateTemplateCommandController
Create a new CreateTemplateCommandController
Sourcepub fn create_schema_controller(&self) -> CreateSchemaCommandController
pub fn create_schema_controller(&self) -> CreateSchemaCommandController
Create a new CreateSchemaCommandController
Sourcepub fn create_docs_controller(&self) -> DocsCommandController
pub fn create_docs_controller(&self) -> DocsCommandController
Create a new DocsCommandController
Sourcepub fn create_provision_controller(&self) -> ProvisionCommandController
pub fn create_provision_controller(&self) -> ProvisionCommandController
Create a new ProvisionCommandController
Sourcepub fn create_destroy_controller(&self) -> DestroyCommandController
pub fn create_destroy_controller(&self) -> DestroyCommandController
Create a new DestroyCommandController
Sourcepub fn create_purge_controller(&self) -> PurgeCommandController
pub fn create_purge_controller(&self) -> PurgeCommandController
Create a new PurgeCommandController
Sourcepub fn create_configure_controller(&self) -> ConfigureCommandController
pub fn create_configure_controller(&self) -> ConfigureCommandController
Create a new ConfigureCommandController
Sourcepub fn create_test_controller(&self) -> TestCommandController
pub fn create_test_controller(&self) -> TestCommandController
Create a new TestCommandController
Sourcepub fn create_validate_controller(&self) -> ValidateCommandController
pub fn create_validate_controller(&self) -> ValidateCommandController
Create a new ValidateCommandController
Sourcepub fn create_register_controller(&self) -> RegisterCommandController
pub fn create_register_controller(&self) -> RegisterCommandController
Create a new RegisterCommandController
Sourcepub fn create_release_controller(&self) -> ReleaseCommandController
pub fn create_release_controller(&self) -> ReleaseCommandController
Create a new ReleaseCommandController
Sourcepub fn create_render_controller(&self) -> RenderCommandController
pub fn create_render_controller(&self) -> RenderCommandController
Create a new RenderCommandController
Sourcepub fn create_run_controller(&self) -> RunCommandController
pub fn create_run_controller(&self) -> RunCommandController
Create a new RunCommandController
Sourcepub fn create_show_controller(&self) -> ShowCommandController
pub fn create_show_controller(&self) -> ShowCommandController
Create a new ShowCommandController
Sourcepub fn create_exists_controller(&self) -> ExistsCommandController
pub fn create_exists_controller(&self) -> ExistsCommandController
Create a new ExistsCommandController
Sourcepub fn create_list_controller(&self) -> ListCommandController
pub fn create_list_controller(&self) -> ListCommandController
Create a new ListCommandController
Sourcepub fn data_directory(&self) -> Arc<Path> ⓘ
pub fn data_directory(&self) -> Arc<Path> ⓘ
Get shared reference to data directory path
Returns an Arc<Path> pointing to the data directory where
environment state files are stored.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Container
impl !UnwindSafe for Container
impl Freeze for Container
impl Send for Container
impl Sync for Container
impl Unpin for Container
impl UnsafeUnpin for Container
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request