Tyrion 1.1.5

dotnet add package Tyrion --version 1.1.5                
NuGet\Install-Package Tyrion -Version 1.1.5                
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="Tyrion" Version="1.1.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tyrion --version 1.1.5                
#r "nuget: Tyrion, 1.1.5"                
#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.
// 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 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. 
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
1.1.5 214 10/23/2023
1.1.4 635 3/30/2020

In this new release, we add some resources, including:
           - Compatibility with dotnet standard applications