Simple.DesignPatterns.Command
8.0.0
dotnet add package Simple.DesignPatterns.Command --version 8.0.0
NuGet\Install-Package Simple.DesignPatterns.Command -Version 8.0.0
<PackageReference Include="Simple.DesignPatterns.Command" Version="8.0.0" />
<PackageVersion Include="Simple.DesignPatterns.Command" Version="8.0.0" />
<PackageReference Include="Simple.DesignPatterns.Command" />
paket add Simple.DesignPatterns.Command --version 8.0.0
#r "nuget: Simple.DesignPatterns.Command, 8.0.0"
#:package Simple.DesignPatterns.Command@8.0.0
#addin nuget:?package=Simple.DesignPatterns.Command&version=8.0.0
#tool nuget:?package=Simple.DesignPatterns.Command&version=8.0.0
Simple.DesignPatterns.Command
Simple.DesignPatterns.Command
is a C# library that implements the boiler plate code for the Command design pattern, so you don't have to recreate it in every project.
This package assumes that your commands are instantiated with data required to execute the command.
If you're unfamiliar with this pattern, you can learn more about it on Wikipedia.
Features
- Command Management: Execute and undo commands using the
CommandManager
. - Logging: Integrated logging using
Microsoft.Extensions.Logging
to track command execution and undo operations. - Asynchronous Operations: Supports asynchronous command execution and undoing.
Requirements
This package assumes
- Use of dependency injection
- Use of logging
Installation
You can install the package via NuGet Package Manager:
Install-Package Simple.DesignPatterns.Command
Or using the .NET CLI:
dotnet add package Simple.DesignPatterns.Command
Usage:
Command Interface
To create a command, implement the ICommand interface:
public class MyCommand : Command
{
public override async Task ExecuteAsync()
{
// Implementation of command execution
}
public override async Task UndoAsync()
{
// Implementation of command undo
}
}
Command Manager
Use the CommandManager to execute and undo commands:
using Microsoft.Extensions.Logging;
using Simple.DesignPatterns.Command;
public class Example
{
private readonly ICommandManager<ICommand> _commandManager;
public Example(ILogger<CommandManager> logger)
{
_commandManager = new CommandManager(logger);
}
public async Task Run()
{
try
{
var command = new MyCommand();
await _commandManager.ExecuteAsync(command);
}
catch (Exception ex)
{
// To undo the command
await _commandManager.UndoAsync();
}
}
}
Example
var store = new Store();
var command = new MyCommand(store);
var commandManager = new CommandManager(Logger.Log);
await _commandManager.ExecuteAsync(command);
Logging
The CommandManager logs the execution and undoing of commands. Ensure that you have configured logging in your application to see the logs.
Exception Handling
The CommandManager handles exceptions during command execution and undoing. If a command's undo operation is not implemented, a NotImplementedException will be logged. Other exceptions will be logged as errors.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Logging (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
8.0.0 | 151 | 5/29/2025 |