36 lines
1.8 KiB
Markdown
36 lines
1.8 KiB
Markdown
# MauiProgram
|
|
|
|
**Namespace:** `FrymasterBadgeApp`
|
|
**Type:** `static class`
|
|
**Purpose:** MAUI application bootstrap. Handles dependency injection setup, configuration loading, font registration, and service factory creation.
|
|
|
|
## 📦 Methods
|
|
|
|
### `CreateMauiApp()`
|
|
- **Access:** `public static`
|
|
- **Returns:** `MauiApp`
|
|
- **Behavior:**
|
|
1. Logs startup.
|
|
2. Initializes `MauiAppBuilder`, enables `CommunityToolkit`, and sets fonts (`OpenSans`, `BarcodeFont`).
|
|
3. Calls `LoadConfiguration(builder)`.
|
|
4. Registers services:
|
|
- `SqlService`: Factory-resolves connection string from `IConfiguration`. Falls back to hardcoded `Server=127.0.0.1...` if missing. Logs warning.
|
|
- `PrinterService`: Singleton.
|
|
- `AppShell`: Singleton.
|
|
- `EmployeePage`, `CompanyPage`, `SettingsPage`: Transient.
|
|
5. Enables debug logging in `DEBUG` builds.
|
|
6. Builds and returns `MauiApp`.
|
|
|
|
### `LoadConfiguration(MauiAppBuilder builder)`
|
|
- **Access:** `private static`
|
|
- **Behavior:** Configuration fallback chain:
|
|
1. **Primary:** Loads `appsettings.json` via `FileSystem.OpenAppPackageFileAsync()`. Parses and injects into builder.
|
|
2. **Fallback 1:** If file system fails, attempts `Assembly.GetManifestResourceStream("FrymasterBadgeApp.Resources.Raw.appsettings.json")`.
|
|
3. **Fallback 2:** If both fail, silently returns (triggers `SqlService` hardcoded fallback).
|
|
4. Logs success or warnings at each stage.
|
|
|
|
---
|
|
**💡 Developer Notes:**
|
|
- ⚠️ **Security Warning:** Hardcoded fallback connection string (`User Id=sa;Password=YourPassword123;`) should be removed or masked before production deployment.
|
|
- Configuration loading gracefully degrades, preventing app crashes on missing config files.
|
|
- Service lifetimes are appropriately scoped (Singleton for app-wide services, Transient for UI pages). |