ORE Studio 0.0.4
Loading...
Searching...
No Matches
application_context.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_WT_SERVICE_APPLICATION_CONTEXT_HPP
21#define ORES_WT_SERVICE_APPLICATION_CONTEXT_HPP
22
23#include <memory>
24#include "ores.database/domain/context.hpp"
25#include "ores.database/domain/database_options.hpp"
26#include "ores.iam.core/service/account_service.hpp"
27#include "ores.iam.core/service/account_setup_service.hpp"
28#include "ores.iam.core/service/authorization_service.hpp"
29#include "ores.iam.core/service/bootstrap_mode_service.hpp"
30#include "ores.variability.core/service/system_settings_service.hpp"
31#include "ores.variability.api/eventing/system_setting_changed_event.hpp"
32#include "ores.refdata.core/service/currency_service.hpp"
33#include "ores.refdata.core/service/country_service.hpp"
34#include "ores.eventing/service/event_bus.hpp"
35#include "ores.eventing/service/postgres_event_source.hpp"
36
37namespace ores::wt::service {
38
47public:
48 static application_context& instance();
49
50 void initialize(const database::database_options& db_opts);
51 bool is_initialized() const { return initialized_; }
52
58 void start_eventing();
59
65 void stop_eventing();
66
67 database::context& db_context() { return *db_context_; }
68
69 iam::service::account_service& account_service() {
70 return *account_service_;
71 }
72
73 iam::service::account_setup_service& account_setup_service() {
74 return *account_setup_service_;
75 }
76
77 iam::service::authorization_service& authorization_service() {
78 return *authorization_service_;
79 }
80
81 variability::service::system_settings_service& system_settings_service() {
82 return *system_settings_service_;
83 }
84
85 refdata::service::currency_service& currency_service() {
86 return *currency_service_;
87 }
88
89 refdata::service::country_service& country_service() {
90 return *country_service_;
91 }
92
93 bool is_bootstrap_mode() const { return is_bootstrap_mode_; }
94
95private:
96 application_context() = default;
98 application_context& operator=(const application_context&) = delete;
99
100 void setup_services();
101 void setup_eventing();
102 void check_bootstrap_mode();
103
104 bool initialized_ = false;
105 bool is_bootstrap_mode_ = false;
106
107 std::unique_ptr<database::context> db_context_;
108 std::unique_ptr<iam::service::account_service> account_service_;
109 std::unique_ptr<iam::service::account_setup_service> account_setup_service_;
110 std::shared_ptr<iam::service::authorization_service> authorization_service_;
111 std::shared_ptr<variability::service::system_settings_service> system_settings_service_;
112 std::unique_ptr<refdata::service::currency_service> currency_service_;
113 std::unique_ptr<refdata::service::country_service> country_service_;
114
115 // Eventing infrastructure for cross-service cache invalidation
116 std::unique_ptr<eventing::service::event_bus> event_bus_;
117 std::unique_ptr<eventing::service::postgres_event_source> event_source_;
118 eventing::service::subscription flags_subscription_;
119};
120
121}
122
123#endif
Context for the operations on a postgres database.
Definition context.hpp:47
Configuration for database connection.
Definition database_options.hpp:33
RAII handle for managing event subscriptions.
Definition event_bus.hpp:41
Service for managing user accounts including creation, listing, and deletion.
Definition account_service.hpp:39
Centralized service for complete account initialization.
Definition account_setup_service.hpp:42
Service for managing role-based access control (RBAC).
Definition authorization_service.hpp:54
Service for managing countries.
Definition country_service.hpp:42
Service for managing currencies.
Definition currency_service.hpp:43
Service for managing typed system settings.
Definition system_settings_service.hpp:41
Holds all shared services for the ores.wt.service application.
Definition application_context.hpp:46
void stop_eventing()
Stop the event source.
Definition application_context.cpp:150
void start_eventing()
Start the event source to listen for PostgreSQL notifications.
Definition application_context.cpp:141