AzureGems.MediatR.Extensions
3.0.1
dotnet add package AzureGems.MediatR.Extensions --version 3.0.1
NuGet\Install-Package AzureGems.MediatR.Extensions -Version 3.0.1
<PackageReference Include="AzureGems.MediatR.Extensions" Version="3.0.1" />
paket add AzureGems.MediatR.Extensions --version 3.0.1
#r "nuget: AzureGems.MediatR.Extensions, 3.0.1"
// Install AzureGems.MediatR.Extensions as a Cake Addin #addin nuget:?package=AzureGems.MediatR.Extensions&version=3.0.1 // Install AzureGems.MediatR.Extensions as a Cake Tool #tool nuget:?package=AzureGems.MediatR.Extensions&version=3.0.1
AzureGems MediatR Extensions
Extension library for the popular MediatR library by Jimmy Bogard to add clear distinction between requests without any side-effects (aka Reads or Queries) or requests with side-effects (aka Writes or Commands).
Queries and QueryHandlers
Create a Query class and inherit from IQuery<out TResult>
:
public class GetRecipeByName : IQuery<Recipe>
{
public string RecipeName {get; set;}
...
}
To send / execute the query, use the SendQuery()
extension on the standard IMediator
interface.
var yummySpaghetti = new GetRecipeByName()
{
RecipeName = "Spaghetti Bolognese"
}
Recipe recipe = await _mediator.SendQuery(yummySpaghetti);
Create a handler for the GetRecipe
query that executes the required business logic to obtain a result:
public class GetRecipeHandler : IQueryHandler<GetRecipe, Recipe>
{
...
public async Task<Recipe> Handle(GetRecipe query, CancellationToken ct)
{
...
}
}
Commands & CommandHandlers
Create a Command class and inherit from ICommand<out TResult>
:
public class CreateRecipe : ICommand<Guid>
{
public string Name {get; set;}
public string Cuisine {get; set;}
public Ingredient[] Ingredients {get; set;}
...
}
To send / execute the command, use the SendCommand()
extension on the standard IMediator
interface.
var yummySpaghetti = new CreateRecipe()
{
Name = "Spaghetti Bolognese",
Cuisine = "Italian",
Ingredients = new[]
{
new Ingredient() { Name = "Spaghetti", WeightInGrams = "500"},
new Ingredient() { Name = "Bolognese Sauce", VolumeInMilliliters = "500"},
new Ingredient() { Name = "Parmesan cheese", WeightInGrams = "250"},
}
}
Guid recipeId = await _mediator.SendCommand(yummySpaghetti);
Create a handler for the CreateRecipe
command that executes the required business logic:
public class CreateRecipeHandler : ICommandHandler<CreateRecipe, Guid>
{
...
public async Task<Guid> Handle(CreateRecipe cmd, CancellationToken ct)
{
...
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- MediatR (>= 12.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.