3.6 KiB
3.6 KiB
Design Improvement Recommendations
This document outlines suggested improvements for the IGP Fan Reference project to enhance maintainability, performance, and code quality.
1. Code Quality and Maintenance
Centralize and Refactor Configuration
- Hardcoded Strings and IDs: Many strings (like storage keys, event names, and navigation paths) are hardcoded across the application. These should be moved to a central
ConstantsorConfigurationclass. - Data Initialization: In
WebsiteData.cs, the page list is hardcoded with magic numbers for IDs. Consider moving this to a JSON configuration file that can be loaded at runtime. - Localization: While the project has a
Localizations.resxfile, some UI strings (like descriptions inWebsiteData.cs) are still hardcoded. All user-facing text should be moved to resource files.
Standardize Event Handling
- The project uses a manual
Actionsubscription pattern in many services (e.g.,StorageService,TimingService,BuildOrderService). - Recommendation: Consider using standard C# events or a more robust Message Bus pattern (like
IMessengerfrom CommunityToolkit.Mvvm) to reduce boilerplate and avoid memory leaks from missing unsubscriptions.
Fix "TODO"s and Commented-Out Code
- Several files (e.g.,
PageLayout.razor,TimingService.cs) containTODOcomments or large blocks of commented-out code. - Recommendation: Clean up these areas. If a feature (like Light Mode) is planned, track it in a backlog instead of leaving dead code in the UI.
2. Architecture and Design
Dependency Injection Cleanup
- Duplicated Service Registration: In
Program.cs,HttpClientis registered twice. - Service Lifetimes: Most services are registered as
Scoped. In Blazor WASM,ScopedandSingletonbehave similarly, but usingSingletonfor stateless services (likeKeyService) or services that truly span the entire session (likeStorageService) makes the intent clearer.
Decouple Logic from UI
- Portals and Services: The "Portal" pattern used for dialogs is good, but the services (like
EntityDialogService) are directly coupled to the UI state. - Recommendation: Ensure that game logic services (in
Services.Immortal) remain pure and don't depend on UI-specific services unless absolutely necessary.
Improve Type Safety
- Several methods use
intorstringfor types that could be enums (e.g.,webPageTypeinNavigationService,IsPrivatestring inWebPageModel). - Recommendation: Replace magic strings and numbers with strongly typed Enums to prevent runtime errors.
3. Performance and UX
Optimize State Management
StorageServicecallsNotifyDataChanged()frequently. If many components subscribe to this, it could lead to unnecessary re-renders.- Recommendation: Implement more granular notifications or use a state management library if the application complexity grows.
Move CSS to Isolated Files
App.razorcontains a large<style>block.- Recommendation: Move these styles to
App.razor.css(CSS isolation) or a globalapp.cssto keep the Razor file focused on structure and logic.
4. Testing and Validation
Expand Test Coverage
- Unit Tests: While Playwright E2E tests are present, there is a lack of unit tests for the complex calculation logic in
BuildOrderServiceandEconomyService. - Recommendation: Add a unit testing project (xUnit or NUnit) to verify the core algorithms independently of the UI.
- CI/CD: Ensure that tests are automatically run on every Pull Request to catch regressions early.