DandyStrategies 10.0.0
dotnet add package DandyStrategies --version 10.0.0
NuGet\Install-Package DandyStrategies -Version 10.0.0
<PackageReference Include="DandyStrategies" Version="10.0.0" />
<PackageVersion Include="DandyStrategies" Version="10.0.0" />
<PackageReference Include="DandyStrategies" />
paket add DandyStrategies --version 10.0.0
#r "nuget: DandyStrategies, 10.0.0"
#:package DandyStrategies@10.0.0
#addin nuget:?package=DandyStrategies&version=10.0.0
#tool nuget:?package=DandyStrategies&version=10.0.0
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 nothingIStrategyDefinition<TReturn>- synchronous returningTReturnIAsyncStrategyDefinition- asynchronous returning nothingIAsyncStrategyDefinition<TReturn>- asynchronous returningTReturn
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:
- Registering strategies using the
StrategiesConfigurationBuilderduringAddDandyStrategiesat startup.services.AddDandyStrategies(configuration => { configuration.AddStategyDefinition<MyStrategyDefinition>(def => { def.AddStrategy<MyStrategyA>("strat-a"); def.AddStrategy<MyStrategyB>("strat-b"); }); }); - Registering strategies using extensions for the
IServiceCollectioninterface.services.AddStategyDefinition<MyStrategyDefinition>(def => { def.AddStrategy<MyStrategyA>("strat-a"); def.AddStrategy<MyStrategyB>("strat-b"); }); - 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 | Versions 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. |
-
net10.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 |
|---|---|---|
| 10.0.0 | 118 | 7/19/2026 |