origin_app/
application.rs1use crate::module::ModuleRegistry;
2use crate::platform::Platform;
3use origin_domain::Result;
4use serde::Serialize;
5use std::sync::Arc;
6
7#[derive(Debug, Clone, Serialize)]
9#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
10pub struct AppInfo {
11 pub id: String,
12 pub name: String,
13 pub version: String,
14 pub modules: Vec<String>,
16}
17
18#[derive(Debug)]
23pub struct Application {
24 platform: Platform,
25 registry: ModuleRegistry,
26}
27
28impl Application {
29 pub(crate) fn new(platform: Platform, registry: ModuleRegistry) -> Self {
30 Self { platform, registry }
31 }
32
33 pub fn platform(&self) -> &Platform {
34 &self.platform
35 }
36
37 pub fn service<T: Send + Sync + 'static>(&self) -> Option<Arc<T>> {
39 self.registry.service::<T>()
40 }
41
42 pub fn require<T: Send + Sync + 'static>(&self) -> Result<Arc<T>> {
44 self.registry.require::<T>()
45 }
46
47 pub fn modules(&self) -> &[&'static str] {
49 self.registry.module_ids()
50 }
51}