Skip to content

Commit 4aea9db

Browse files
committedJan 17, 2025··
refactor: [torrust#1187] extract fn initialize_app_container
1 parent 747b58d commit 4aea9db

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed
 

‎src/bootstrap/app.rs

+23-18
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,13 @@ pub fn setup() -> (Configuration, AppContainer) {
4848
panic!("Configuration error: {e}");
4949
}
5050

51-
// Initialize services
52-
53-
let (stats_event_sender, stats_repository) = statistics::setup::factory(configuration.core.tracker_usage_statistics);
54-
let stats_event_sender = Arc::new(stats_event_sender);
55-
let stats_repository = Arc::new(stats_repository);
56-
57-
let ban_service = Arc::new(RwLock::new(BanService::new(MAX_CONNECTION_ID_ERRORS_PER_IP)));
58-
59-
let tracker = initialize_globals_and_tracker(&configuration);
51+
initialize_global_services(&configuration);
6052

6153
tracing::info!("Configuration:\n{}", configuration.clone().mask_secrets().to_json());
6254

63-
(
64-
configuration,
65-
AppContainer {
66-
tracker,
67-
ban_service,
68-
stats_event_sender,
69-
stats_repository,
70-
},
71-
)
55+
let app_container = initialize_app_container(&configuration);
56+
57+
(configuration, app_container)
7258
}
7359

7460
/// checks if the seed is the instance seed in production.
@@ -100,6 +86,25 @@ pub fn initialize_global_services(configuration: &Configuration) {
10086
initialize_logging(configuration);
10187
}
10288

89+
/// It initializes the stIoC Container.
90+
#[instrument(skip())]
91+
pub fn initialize_app_container(configuration: &Configuration) -> AppContainer {
92+
let (stats_event_sender, stats_repository) = statistics::setup::factory(configuration.core.tracker_usage_statistics);
93+
let stats_event_sender = Arc::new(stats_event_sender);
94+
let stats_repository = Arc::new(stats_repository);
95+
96+
let ban_service = Arc::new(RwLock::new(BanService::new(MAX_CONNECTION_ID_ERRORS_PER_IP)));
97+
98+
let tracker = Arc::new(initialize_tracker(configuration));
99+
100+
AppContainer {
101+
tracker,
102+
ban_service,
103+
stats_event_sender,
104+
stats_repository,
105+
}
106+
}
107+
103108
/// It initializes the application static values.
104109
///
105110
/// These values are accessible throughout the entire application:

0 commit comments

Comments
 (0)
Please sign in to comment.