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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Simple.DesignPatterns.Command" Version="8.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Simple.DesignPatterns.Command" Version="8.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Simple.DesignPatterns.Command" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Simple.DesignPatterns.Command --version 8.0.0
                    
#r "nuget: Simple.DesignPatterns.Command, 8.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Simple.DesignPatterns.Command@8.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Simple.DesignPatterns.Command&version=8.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Simple.DesignPatterns.Command&version=8.0.0
                    
Install as a Cake Tool

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

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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