(vision) SCS/DDD
This commit is contained in:
@@ -12,20 +12,48 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import at.mocode.config.AppServiceConfiguration
|
||||
import at.mocode.config.ThemeService
|
||||
import at.mocode.di.ServiceRegistry
|
||||
import at.mocode.di.resolve
|
||||
import org.jetbrains.compose.ui.tooling.preview.Preview
|
||||
|
||||
@Composable
|
||||
@Preview
|
||||
fun App() {
|
||||
MaterialTheme(
|
||||
colors = lightColors(
|
||||
primary = Color(0xFF2E7D32),
|
||||
primaryVariant = Color(0xFF1B5E20),
|
||||
secondary = Color(0xFF8BC34A),
|
||||
background = Color(0xFFF1F8E9)
|
||||
)
|
||||
) {
|
||||
HomePage()
|
||||
// State to track if services are initialized
|
||||
var servicesInitialized by remember { mutableStateOf(false) }
|
||||
|
||||
// Initialize services when the app starts
|
||||
LaunchedEffect(Unit) {
|
||||
AppServiceConfiguration.configureAppServices()
|
||||
servicesInitialized = true
|
||||
}
|
||||
|
||||
// Only show the app content after services are initialized
|
||||
if (servicesInitialized) {
|
||||
// Get theme service to demonstrate ServiceLocator usage
|
||||
val themeService: ThemeService = ServiceRegistry.serviceLocator.resolve()
|
||||
val currentTheme by remember { mutableStateOf(themeService.getCurrentTheme()) }
|
||||
|
||||
MaterialTheme(
|
||||
colors = lightColors(
|
||||
primary = Color(0xFF2E7D32),
|
||||
primaryVariant = Color(0xFF1B5E20),
|
||||
secondary = Color(0xFF8BC34A),
|
||||
background = Color(0xFFF1F8E9)
|
||||
)
|
||||
) {
|
||||
HomePage()
|
||||
}
|
||||
} else {
|
||||
// Show loading state while services are being initialized
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +72,7 @@ fun HomePage() {
|
||||
}
|
||||
|
||||
item {
|
||||
// Welcome Card
|
||||
// Welcome, Card
|
||||
WelcomeCard()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package at.mocode.config
|
||||
|
||||
import at.mocode.di.ServiceRegistry
|
||||
import at.mocode.di.register
|
||||
|
||||
/**
|
||||
* Service configuration for the Compose application.
|
||||
* Demonstrates how to use the ServiceLocator pattern in the frontend.
|
||||
*/
|
||||
object AppServiceConfiguration {
|
||||
|
||||
/**
|
||||
* Initialize services for the compose application
|
||||
*/
|
||||
fun configureAppServices() {
|
||||
val serviceLocator = ServiceRegistry.serviceLocator
|
||||
|
||||
// Register frontend-specific services
|
||||
registerUIServices(serviceLocator)
|
||||
|
||||
// Register API clients or other services as needed
|
||||
// registerApiServices(serviceLocator)
|
||||
}
|
||||
|
||||
/**
|
||||
* Register UI-related services
|
||||
*/
|
||||
private fun registerUIServices(serviceLocator: at.mocode.di.ServiceLocator) {
|
||||
// Example: Register a theme service
|
||||
serviceLocator.register<ThemeService> { DefaultThemeService() }
|
||||
|
||||
// Example: Register a navigation service
|
||||
serviceLocator.register<NavigationService> { DefaultNavigationService() }
|
||||
|
||||
// Add more UI services as needed
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all registered services (useful for testing)
|
||||
*/
|
||||
fun clearAppServices() {
|
||||
ServiceRegistry.serviceLocator.clear()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Example theme service interface
|
||||
*/
|
||||
interface ThemeService {
|
||||
fun getCurrentTheme(): String
|
||||
fun setTheme(theme: String)
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation of ThemeService
|
||||
*/
|
||||
class DefaultThemeService : ThemeService {
|
||||
private var currentTheme = "light"
|
||||
|
||||
override fun getCurrentTheme(): String = currentTheme
|
||||
|
||||
override fun setTheme(theme: String) {
|
||||
currentTheme = theme
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Example navigation service interface
|
||||
*/
|
||||
interface NavigationService {
|
||||
fun navigateTo(route: String)
|
||||
fun goBack()
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation of NavigationService
|
||||
*/
|
||||
class DefaultNavigationService : NavigationService {
|
||||
override fun navigateTo(route: String) {
|
||||
// Implementation for navigation
|
||||
println("Navigating to: $route")
|
||||
}
|
||||
|
||||
override fun goBack() {
|
||||
// Implementation for going back
|
||||
println("Going back")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user