{"id":22886391,"url":"https://github.com/simplesoft-pt/mediator","last_synced_at":"2025-05-07T10:30:18.037Z","repository":{"id":40909259,"uuid":"100081126","full_name":"simplesoft-pt/Mediator","owner":"simplesoft-pt","description":"Small .NET library that helps with the implementation of mediator pattern for commands, events and queries","archived":false,"fork":false,"pushed_at":"2022-12-08T09:07:12.000Z","size":914,"stargazers_count":39,"open_issues_count":2,"forks_count":9,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-05-29T21:32:04.163Z","etag":null,"topics":["csharp","dotnet","dotnet-core","mediator","netcore","patterns"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simplesoft-pt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-12T01:23:30.000Z","updated_at":"2024-03-23T12:33:33.000Z","dependencies_parsed_at":"2023-01-25T02:30:55.183Z","dependency_job_id":null,"html_url":"https://github.com/simplesoft-pt/Mediator","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplesoft-pt%2FMediator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplesoft-pt%2FMediator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplesoft-pt%2FMediator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplesoft-pt%2FMediator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplesoft-pt","download_url":"https://codeload.github.com/simplesoft-pt/Mediator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229608897,"owners_count":18098089,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","dotnet-core","mediator","netcore","patterns"],"created_at":"2024-12-13T20:18:30.337Z","updated_at":"2024-12-13T20:18:31.030Z","avatar_url":"https://github.com/simplesoft-pt.png","language":"C#","readme":"# Mediator\nSmall .NET library that helps with the implementation of mediator pattern for commands, events and queries.\n\nUsing a mediator instance, send commands, broadcast events and fetch queries from their respective generic handlers.\n\n## Articles\n\n* [Introduction to the mediator pattern in ASP.NET Core applications](https://medium.com/swlh/mediator-pattern-in-asp-net-core-applications-109b4231c0f8)\n* [Using Mediator Pipelines in ASP.NET Core Applications](https://medium.com/swlh/mediator-pattern-in-asp-net-core-applications-pipelines-ec0926e71bc8)\n* [Validation with Mediator Pipelines in ASP.NET Core Applications](https://medium.com/swlh/validation-with-mediator-pipelines-in-asp-net-core-applications-7878a56ec604)\n* [Transaction Management with Mediator Pipelines in ASP.NET Core](https://medium.com/swlh/transaction-management-with-mediator-pipelines-in-asp-net-core-39317a19bb8d)\n* [Auditing with Mediator Pipelines in ASP.NET Core](https://joaoprsimoes.medium.com/auditing-with-mediator-pipelines-in-asp-net-core-be34cf3551b)\n\n\n## Installation\nThe library is available via [NuGet](https://www.nuget.org/packages?q=SimpleSoft.Mediator) packages:\n\n| NuGet | Description | Version |\n| --- | --- | --- |\n| [SimpleSoft.Mediator.Abstractions](https://www.nuget.org/packages/simplesoft.mediator.abstractions) | interfaces and abstract implementations (commands, events, queries, mediator, ...) | [![NuGet](https://img.shields.io/nuget/vpre/simplesoft.mediator.abstractions.svg)](https://www.nuget.org/packages/simplesoft.mediator.abstractions) |\n| [SimpleSoft.Mediator](https://www.nuget.org/packages/simplesoft.mediator) | core implementation | [![NuGet](https://img.shields.io/nuget/vpre/simplesoft.mediator.svg)](https://www.nuget.org/packages/simplesoft.mediator) |\n| [SimpleSoft.Mediator.Microsoft.Extensions](https://www.nuget.org/packages/simplesoft.mediator.microsoft.extensions) | specialized methods and classes for the Microsoft dependency injection container and logging facades | [![NuGet](https://img.shields.io/nuget/vpre/simplesoft.mediator.microsoft.extensions.svg)](https://www.nuget.org/packages/simplesoft.mediator.microsoft.extensions) |\n| [SimpleSoft.Mediator.Microsoft.Extensions.DatabaseTransactionPipeline](https://www.nuget.org/packages/simplesoft.mediator.microsoft.extensions.databasetransactionpipeline) | mediator pipeline to enforce SimpleSoft.Database transactions | [![NuGet](https://img.shields.io/nuget/vpre/simplesoft.mediator.microsoft.extensions.databasetransactionpipeline.svg)](https://www.nuget.org/packages/simplesoft.mediator.microsoft.extensions.databasetransactionpipeline) |\n| [SimpleSoft.Mediator.Microsoft.Extensions.EFCoreTransactionPipeline](https://www.nuget.org/packages/simplesoft.mediator.microsoft.extensions.efcoretransactionpipeline) | mediator pipeline to enforce Entity Framework Core transactions | [![NuGet](https://img.shields.io/nuget/vpre/simplesoft.mediator.microsoft.extensions.efcoretransactionpipeline.svg)](https://www.nuget.org/packages/simplesoft.mediator.microsoft.extensions.efcoretransactionpipeline) |\n| [SimpleSoft.Mediator.Microsoft.Extensions.LoggingPipeline](https://www.nuget.org/packages/simplesoft.mediator.microsoft.extensions.loggingpipeline) | pipeline that serializes commands, queries, events and results into the logging | [![NuGet](https://img.shields.io/nuget/vpre/simplesoft.mediator.microsoft.extensions.loggingpipeline.svg)](https://www.nuget.org/packages/simplesoft.mediator.microsoft.extensions.loggingpipeline) |\n| [SimpleSoft.Mediator.Microsoft.Extensions.ValidationPipeline](https://www.nuget.org/packages/simplesoft.mediator.microsoft.extensions.validationpipeline) | pipeline that enforces validation into commands, queries and events before entering the handlers by using `FluentValidation` | [![NuGet](https://img.shields.io/nuget/vpre/simplesoft.mediator.microsoft.extensions.validationpipeline.svg)](https://www.nuget.org/packages/simplesoft.mediator.microsoft.extensions.validationpipeline) |\n\n### Package Manager\n```powershell\nInstall-Package SimpleSoft.Mediator.Abstractions\nInstall-Package SimpleSoft.Mediator\nInstall-Package SimpleSoft.Mediator.Microsoft.Extensions\nInstall-Package SimpleSoft.Mediator.Microsoft.Extensions.DatabaseTransactionPipeline\nInstall-Package SimpleSoft.Mediator.Microsoft.Extensions.EFCoreTransactionPipeline\nInstall-Package SimpleSoft.Mediator.Microsoft.Extensions.LoggingPipeline\nInstall-Package SimpleSoft.Mediator.Microsoft.Extensions.ValidationPipeline\n```\n\n### .NET CLI\n```powershell\ndotnet add package SimpleSoft.Mediator.Abstractions\ndotnet add package SimpleSoft.Mediator\ndotnet add package SimpleSoft.Mediator.Microsoft.Extensions\ndotnet add package SimpleSoft.Mediator.Microsoft.Extensions.DatabaseTransactionPipeline\ndotnet add package SimpleSoft.Mediator.Microsoft.Extensions.EFCoreTransactionPipeline\ndotnet add package SimpleSoft.Mediator.Microsoft.Extensions.LoggingPipeline\ndotnet add package SimpleSoft.Mediator.Microsoft.Extensions.ValidationPipeline\n```\n## Compatibility\nThis library is compatible with the following frameworks:\n\n* `SimpleSoft.Mediator.Abstractions`\n  * .NET Framework 4.0+;\n  * .NET Standard 1.0+;\n* `SimpleSoft.Mediator`\n  * .NET Framework 4.0+;\n  * .NET Standard 1.0+;\n* `SimpleSoft.Mediator.Microsoft.Extensions`\n  * .NET Standard 1.1+;\n* `SimpleSoft.Mediator.Microsoft.Extensions.DatabaseTransactionPipeline`\n  * .NET Standard 1.1+;\n* `SimpleSoft.Mediator.Microsoft.Extensions.EFCoreTransactionPipeline`\n  * .NET Standard 1.3+;\n* `SimpleSoft.Mediator.Microsoft.Extensions.LoggingPipeline`\n  * .NET Standard 1.1+;\n* `SimpleSoft.Mediator.Microsoft.Extensions.ValidationPipeline`\n  * .NET Standard 1.1+;\n\n## Usage\nDocumentation is available via [wiki](https://github.com/simplesoft-pt/Mediator/wiki) or you can check the [working](https://github.com/simplesoft-pt/Mediator/tree/master/work/) examples or [test](https://github.com/simplesoft-pt/Mediator/tree/master/test) code.\n\nHere is an example of a command handler that also sends some events:\n```csharp\npublic class CreateUserCommand : Command {\n  public string Email { get; set; }\n  public string Password { get; set; }\n}\n\npublic class UserCreatedEvent : Event {\n  public User User { get; set; }\n}\n\npublic class UserByIdQuery : Query\u003cUser\u003e {\n  public Guid UserId { get; set; }\n}\n\npublic class User {\n  public Guid Id { get; set; }\n  public string Email { get; set; }\n}\n\npublic class ExampleHandlers : ICommandHandler\u003cCreateUserCommand\u003e, IQueryHandler\u003cUserByIdQuery,User\u003e {\n  \n  private readonly IMediator _mediator;\n  \n  public UsersService(IMediator mediator) {\n    _mediator = mediator;\n  }\n  \n  public async Task HandleAsync(CreateUserCommand cmd, CancellationToken ct) {\n    var userId = Guid.NewGuid();\n    \n    // try add the user to some store\n    \n    await _mediator.BroadcastAsync(new UserCreatedEvent {\n      User = new User {\n        Id = userId,\n        Email = cmd.Email\n      }\n    }, ct);\n  }\n  \n  public async Task\u003cUser\u003e HandleAsync(UserByIdQuery query, CancellationToken ct) {\n    User user = null;\n    \n    // search the store by user id\n    \n    return user;\n  }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplesoft-pt%2Fmediator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplesoft-pt%2Fmediator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplesoft-pt%2Fmediator/lists"}