DandyStrategies 10.0.0

dotnet add package DandyStrategies --version 10.0.0
                    
NuGet\Install-Package DandyStrategies -Version 10.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="DandyStrategies" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DandyStrategies" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DandyStrategies" />
                    
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 DandyStrategies --version 10.0.0
                    
#r "nuget: DandyStrategies, 10.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 DandyStrategies@10.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=DandyStrategies&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DandyStrategies&version=10.0.0
                    
Install as a Cake Tool

Whats DandyStrategies?

A small framework for streamlining the use of the strategy design pattern in C# .NET Core using yet another interpretation of the mediator design pattern.

Setup and use

Implementing strategies

Before implementing strategies you need to write a strategy definiton, by implementing one of these interfaces, depending on your need:

  • IStrategyDefinition - synchronous returning nothing
  • IStrategyDefinition<TReturn> - synchronous returning TReturn
  • IAsyncStrategyDefinition - asynchronous returning nothing
  • IAsyncStrategyDefinition<TReturn> - asynchronous returning TReturn

An implemented series of strategies for one definition could look like this:

internal static class MyStrategy
{
    public sealed record Definition(object Key) : IStrategyDefinition;

    [StrategyKey("a")]
    public sealed class StrategyA : IStrategy<Definition>
    {
        public void Execute(Definition definition)
        {
        }
    }
    
    [StrategyKey("b")]
    public sealed class StrategyB : IStrategy<Definition>
    {
        public void Execute(Definition definition)
        {
        }
    }
}

But of course you can structure your classes differently as well.

Executing strategies

To execute the strategies you have to inject the IStrategyExecutor and instantiate a strategy definition. The executor allows you to throw in the strategy definition and figures out what strategy to run.

internal sealed class MyService(IStrategyExecutor executor)
{
    public void MyCoolMethod(string donaldTrumpIsInTheEpsteinFiles)
    {
        var definition = new MyStrategy.Definition(donaldTrumpIsInTheEpsteinFiles);
        executor.Execute(definition);
    }
}

Setup

As expected there is an extension method for the IServiceCollection interface that registers required services and allows to configure automatic registration of strategies via assembly scanning (more on that down below).

The extension exposes an action for configuring the framework via the StrategiesConfigurationBuilder, which allows you to setup assembly scanning, but also allows registering strategies.

builder.ervices.AddDandyStrategies(configuration =>
{
    // Registering strategies or assembly scanning and alike...
);

Registering strategies

You can register strategies in three ways:

  1. Registering strategies using the StrategiesConfigurationBuilder during AddDandyStrategies at startup.
    services.AddDandyStrategies(configuration =>
     {
         configuration.AddStategyDefinition<MyStrategyDefinition>(def =>
         {
             def.AddStrategy<MyStrategyA>("strat-a");
             def.AddStrategy<MyStrategyB>("strat-b");
         });
     });
    
  2. Registering strategies using extensions for the IServiceCollection interface.
    services.AddStategyDefinition<MyStrategyDefinition>(def =>
    {
        def.AddStrategy<MyStrategyA>("strat-a");
        def.AddStrategy<MyStrategyB>("strat-b");
    });
    
  3. Registering strategies using assembly scanning and the StrategyKeyAttribute (down below).

No matter how you decide to register your strategies, they are always registered keyed for their respective interface type from above. So theoretically you could also manually register everything using just IServiceCollection.AddKeyedTransient() (even after already running through previous registrations for a given strategy definition).

Assembly scanning and StrategyKeyAttribute

In order to scan for strategies and register them automatically they need to be adorned with the StrategyKeyAttribute and the respective key the strategy is supposed to be associated with.

Additionally you need to specify what assemblies to scan in and you should be set.

services.AddDandyStrategies(cfg =>
{
    cfg.ScanInAssemblies(GetType().Assembly);
});
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
10.0.0 118 7/19/2026