Tyrion 1.1.4

Tyrion is a mediator implementation for .Net Core

Install-Package Tyrion -Version 1.1.4
dotnet add package Tyrion --version 1.1.4
<PackageReference Include="Tyrion" Version="1.1.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tyrion --version 1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

โš”๏ธ Tyrion.CQRS

Build status
Build Status
GitHub license
NuGet
NuGet
Codacy Badge

Tyrion is an implementation of mediator pattern for .Net Core

๐Ÿ‘จ๐Ÿฝโ€๐Ÿ’ป 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

Twitter: @lucasluizss

๐Ÿ“ Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

โš–๏ธ License

MIT

โš”๏ธ Tyrion.CQRS

Build status
Build Status
GitHub license
NuGet
NuGet
Codacy Badge

Tyrion is an implementation of mediator pattern for .Net Core

๐Ÿ‘จ๐Ÿฝโ€๐Ÿ’ป 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

Twitter: @lucasluizss

๐Ÿ“ Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

โš–๏ธ License

MIT

Release Notes

In this new release we add some resources, included:
1 - Notification events

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.4 166 3/30/2020