Tyrion 1.1.5
dotnet add package Tyrion --version 1.1.5
NuGet\Install-Package Tyrion -Version 1.1.5
<PackageReference Include="Tyrion" Version="1.1.5" />
paket add Tyrion --version 1.1.5
#r "nuget: Tyrion, 1.1.5"
// Install Tyrion as a Cake Addin #addin nuget:?package=Tyrion&version=1.1.5 // Install Tyrion as a Cake Tool #tool nuget:?package=Tyrion&version=1.1.5
Tyrion is an implementation of mediator pattern for dotnet
๐จ๐ฝโ๐ป Installing
- Package Manager
Install-Package Tyrion
- .Net CLI
dotnet add package Tyrion
- Pakat CLI
paket add Tyrion
๐งพ Usage
In your Startup.cs, add Tyrion on your service with some typeof class, for identify the currently assembly project. (Could be any class in your project) like this:
services.AddTyrion(typeof(Category));
When we talk about mediator everything is about requests... Tyrion is abstract for just one interface, where you will handle with multiple concepts types implementing just the IRequest interface for Commands and Queries and INotification interface when you want send multiple notifications events.
You must keep it simple, so when you are creating a CommandHandle you have to combine your Command request. That way, Tyrion can find quickly the required implementation.
Samples of requests bellow:
public class ProductCommand : IRequest { }
public class CategoryQuery : IRequest { }
public class CategoryAddedEvent : INotification { }
Samples of validation requests bellow (this is an optional implementation):
public sealed class CategoryCommandValidator : Validator<CategoryCommand>
{
public CategoryCommandValidator()
{
RuleFor(x => x.Name).NotEmpty();
}
}
Samples of Handlers bellow:
public sealed class CategoryCommandHandler : IRequestHandler<CategoryCommand, Category>
{
public async Task<IResult<Category>> Execute(CategoryCommand command)
{
return await Result<Category>.SuccessedAsync(new Category());
}
}
public sealed class CategoryQueryHandler : IRequestHandler<CategoryQuery, Category>
{
public async Task<IResult<Category>> Execute(CategoryQuery request)
{
return await Result<Category>.SuccessedAsync(new Category());
}
}
public sealed class CategoryNotificationHandler : INotificationHandler<CategoryAddedEvent>
{
public async Task Publish(CategoryAddedEvent notification)
{
await Task.CompletedTask;
}
}
IRequestHandler an receive one or two generics arguments, the first one is your request (Command, Query, etc) all implementing IRequest and the secound one is you return type if you need.
Case you implement your request validation (using Validator<> class), Tyrion will handle with the validation and return your errors automaticaly.
That way we can assunrency that we will receive what we are requiring.
Tyrion allows you to implement multiple handlers in your application service. Just in case you need keep the same context together.
Something like this:
public sealed class ProductCommandHandler : IRequestHandler<SaveProductCommand, Product>,
IRequestHandler<UpdateProductCommand, Product>,
IRequestHandler<RemoveProductCommand>,
IRequestHandler<InativeProductCommand>
{
public async Task<IResult<Product>> Execute(SaveProductCommand request)
{
return await Result<Product>.SuccessedAsync(new Product());
}
public async Task<IResult<Product>> Execute(UpdateProductCommand command)
{
return await Result<Product>.SuccessedAsync(new Product());
}
public async Task<IResult> Execute(RemoveProductCommand request)
{
return await Result.SuccessedAsync(new Product());
}
public async Task<IResult> Execute(InativeProductCommand request)
{
return await Result.SuccessedAsync();
}
}
I hope you enjoy this. I will work to include little improvements!
๐๐ฝโโ๏ธ Author
X: @lucasluizss
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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- FluentValidation (>= 11.8.0)
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.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.
In this new release, we add some resources, including:
- Compatibility with dotnet standard applications