A robust, enterprise-grade C# console application demonstrating the Command Design Pattern and Dependency Injection with a "Fortress" architecture. This project allows users to perform arithmetic operations with full Undo capabilities.
This solution is divided into two distinct layers to ensure strict Separation of Concerns and Data Integrity:
-
CommandProcessor.Core (Class Library): The "Fortress." All business logic, the Calculator state, and specific ICommand implementations are marked as internal. They are inaccessible to the UI, preventing external tampering.
-
CommandProcessor.Console (Console App): The UI layer. It interacts only with the ICommandManager interface and is responsible for user input and output.
-
CommandProcessor.Tests (xUnit): A comprehensive suite of unit tests to verify the Undo stack and DI container registration.
-
Command Pattern: Encapsulates requests as objects.
-
Service Locator (via IoC): Used within the Manager to resolve commands.
-
Facade: The CommandManager acts as the single point of entry for the Core library.
-
Undo Support: Every command is reversible. The system uses a LIFO (Last-In-First-Out) stack to track operations.
-
Modern DI (.NET 10): Leverages Keyed Services to resolve commands dynamically at runtime based on user input.
-
Type Safety: Uses Enums for command identification instead of error-prone magic strings.
-
Unit Tested: Isolated testing of the Command Manager.
| Command | Description |
|---|---|
| increment | Adds 1 to the current value. |
| decrement | Subtracts 1 from the current value. |
| double | Multiplies the current value by 2. |
| randadd | Adds a random number (1-100) to the value. |
| undo | Reverts the last operation. |
| exit | Terminates the application. |
Prerequisites
✅ .NET 9.0 SDK (or later)
✅ Visual Studio 2022 / VS Code
The solution includes xUnit tests that verify the internal logic of the core library.
Contributions are welcome! Please ensure that any PR maintains the "Green" status of the Tests.
Aman Toumaj Senior Software Developer & Architecture Enthusiast