{"id":29406285,"url":"https://github.com/asantacroce/dom.mediator","last_synced_at":"2026-05-18T11:09:43.508Z","repository":{"id":303971712,"uuid":"1017363960","full_name":"asantacroce/dom.mediator","owner":"asantacroce","description":"Lightweight mediator pattern for .NET with pipeline support and native Result Pattern. Built for minimal APIs and Clean Architecture.","archived":false,"fork":false,"pushed_at":"2026-01-27T09:25:33.000Z","size":719,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-22T19:18:42.917Z","etag":null,"topics":["cqrs","csharp","dotnet","mediator","minimal-api","pipeline","result-pattern"],"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/asantacroce.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-10T12:23:37.000Z","updated_at":"2026-01-27T09:24:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"0b0ec4d4-a8c8-4420-bc81-b17b82e4fa21","html_url":"https://github.com/asantacroce/dom.mediator","commit_stats":null,"previous_names":["asantacroce/dom.mediator"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/asantacroce/dom.mediator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asantacroce%2Fdom.mediator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asantacroce%2Fdom.mediator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asantacroce%2Fdom.mediator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asantacroce%2Fdom.mediator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asantacroce","download_url":"https://codeload.github.com/asantacroce/dom.mediator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asantacroce%2Fdom.mediator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33175953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"ssl_error","status_checked_at":"2026-05-18T09:27:28.300Z","response_time":71,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cqrs","csharp","dotnet","mediator","minimal-api","pipeline","result-pattern"],"created_at":"2025-07-10T23:19:52.118Z","updated_at":"2026-05-18T11:09:43.503Z","avatar_url":"https://github.com/asantacroce.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿[![NuGet](https://img.shields.io/nuget/v/Dom.Mediator.svg)](https://www.nuget.org/packages/Dom.Mediator)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](../LICENSE)\n\n# Dom.Mediator\n\n**Dom.Mediator** is a clean, minimal implementation of the Mediator pattern for .NET, focused on:\n\n- ✅ Request/Response messaging (CQRS)\n- ✅ Composable pipeline behaviors (validation, logging, etc.)\n- ✅ Built-in Result Pattern handling with typed errors\n- ✅ Lightweight with minimal dependencies\n- ✅ Perfect fit for Minimal APIs or Clean Architecture\n\n## 📦 Install via NuGet\n\n```bash\ndotnet add package Dom.Mediator\n```\n\n## 🚀 Quick Example\n\n### Commands (Actions without return values)\n\nDefine your command:\n```csharp\npublic record CreateTaskCommand(string Title, string? Description) : ICommand;\n```\n\nCreate a handler:\n```csharp\npublic class CreateTaskHandler : ICommandHandler\u003cCreateTaskCommand\u003e\n{\n    public Task\u003cResult\u003e Handle(CreateTaskCommand command, CancellationToken cancellationToken)\n    {\n        // Perform action logic here\n        return Task.FromResult(Result.Success());\n    }\n}\n```\n\n### Queries (Read operations with return values)\n\nDefine your query:\n```csharp\npublic record GetTasksQuery() : IQuery\u003cList\u003cTaskItem\u003e\u003e;\n```\n\nCreate a handler:\n```csharp\npublic class GetTasksHandler : IQueryHandler\u003cGetTasksQuery, List\u003cTaskItem\u003e\u003e\n{\n    public Task\u003cResult\u003cList\u003cTaskItem\u003e\u003e\u003e Handle(GetTasksQuery query, CancellationToken cancellationToken)\n    {\n        var tasks = GetTasksFromStore(); // Your logic here\n        return Task.FromResult(Result\u003cList\u003cTaskItem\u003e\u003e.Success(tasks));\n    }\n}\n```\n\n### Setup with Dependency Injection\n\n```csharp\nbuilder.Services.AddMediator(config =\u003e\n{\n    config.RegisterHandlers(typeof(Program).Assembly);\n    \n    // Add pipeline behaviors - automatically handles both queries and commands\n    config.AddBehaviour(typeof(LoggingBehaviour\u003c,\u003e));  // For queries (request/response)\n    config.AddBehaviour(typeof(LoggingBehaviour\u003c\u003e));   // For commands (no response)\n});\n```\n\n## 📚 Samples \u0026 Tests\n\nCheck out the [**samples**](https://github.com/asantacroce/dom.mediator/tree/main/samples) directory for complete working examples:\n\n\u003e 🧪 **Testing**: See the [**tests**](https://github.com/asantacroce/dom.mediator/tree/main/tests) directory for unit tests, coverage reports, and testing documentation.\n\n\u003e 📊 **Coverage**: Here also the [**coverage report**](https://mediator.andresantacroce.com/coverage/) related to the latest version.\n\n### 🌐 [Minimal API Sample](https://github.com/asantacroce/dom.mediator/tree/main/samples/Dom.Mediator.Samples.MinimalApi)\nA complete ASP.NET Core Minimal API implementation demonstrating:\n- **Task Management API** with CQRS pattern\n- **Command \u0026 Query handlers** with validation\n- **Pipeline behaviors** for logging and cross-cutting concerns\n- **Result pattern** integration with HTTP responses\n- **Swagger documentation** and endpoint configuration\n\n```bash\ncd samples/Dom.Mediator.Samples.MinimalApi\ndotnet run\n```\n\n## ⚙️ Built-in Features\n\n- 🧱 **Pipeline Behaviors**: Add logging, validation, error handling in a clean chain\n- 🎯 **Result Pattern**: Native success/failure with structured error codes (`Result\u003cT\u003e` and `Result`)\n- 🔄 **Auto-Handler Discovery**: Reflective scanning via assembly registration\n- 💡 **CQRS Support**: Separate Command and Query handling with distinct interfaces\n- 🏗️ **Dependency Injection**: Built-in support for Microsoft DI container\n\n## 🧩 Pipeline Behaviors\n\nAdd behaviors to intercept and process requests using a unified registration method:\n\n```csharp\n// Single registration method for both query and command behaviors\nconfig.AddBehaviour(typeof(LoggingBehaviour\u003c,\u003e));      // For queries (2 generic parameters)\nconfig.AddBehaviour(typeof(ValidationBehaviour\u003c\u003e));    // For commands (1 generic parameter)\n```\n\nThe mediator automatically detects whether your behavior is for:\n- **Queries** (request/response) - behaviors with 2 generic type parameters\n- **Commands** (no response) - behaviors with 1 generic type parameter\n\n### Query Behavior Interface (Request/Response):\n```csharp\npublic interface IPipelineBehavior\u003cTRequest, TResponse\u003e\n    where TRequest : IRequest\u003cTResponse\u003e\n{\n    Task\u003cResult\u003cTResponse\u003e\u003e Handle(\n        TRequest request, \n        CancellationToken cancellationToken, \n        RequestHandlerDelegate\u003cTResponse\u003e next);\n}\n```\n\n### Command Behavior Interface (No Response):\n```csharp\npublic interface IPipelineBehavior\u003cTCommand\u003e\n    where TCommand : ICommand\n{\n    Task\u003cResult\u003e Handle(\n        TCommand command, \n        CancellationToken cancellationToken, \n        CommandHandlerDelegate next);\n}\n```\n\n### Example Behavior Implementation:\n```csharp\n// Query behavior (2 generic parameters)\npublic class LoggingBehaviour\u003cTRequest, TResponse\u003e : IPipelineBehavior\u003cTRequest, TResponse\u003e\n    where TRequest : IRequest\u003cTResponse\u003e\n{\n    private readonly ILogger\u003cLoggingBehaviour\u003cTRequest, TResponse\u003e\u003e _logger;\n\n    public LoggingBehaviour(ILogger\u003cLoggingBehaviour\u003cTRequest, TResponse\u003e\u003e logger)\n        =\u003e _logger = logger;\n\n    public async Task\u003cResult\u003cTResponse\u003e\u003e Handle(\n        TRequest request,\n        CancellationToken cancellationToken,\n        RequestHandlerDelegate\u003cTResponse\u003e next)\n    {\n        _logger.LogInformation(\"Handling {RequestType}\", typeof(TRequest).Name);\n        var response = await next();\n        _logger.LogInformation(\"Handled {RequestType}\", typeof(TRequest).Name);\n        return response;\n    }\n}\n\n// Command behavior (1 generic parameter)\npublic class LoggingBehaviour\u003cTCommand\u003e : IPipelineBehavior\u003cTCommand\u003e\n    where TCommand : ICommand\n{\n    private readonly ILogger\u003cLoggingBehaviour\u003cTCommand\u003e\u003e _logger;\n\n    public LoggingBehaviour(ILogger\u003cLoggingBehaviour\u003cTCommand\u003e\u003e logger)\n        =\u003e _logger = logger;\n\n    public async Task\u003cResult\u003e Handle(\n        TCommand command,\n        CancellationToken cancellationToken,\n        CommandHandlerDelegate next)\n    {\n        _logger.LogInformation(\"Handling {CommandType}\", typeof(TCommand).Name);\n        var response = await next();\n        _logger.LogInformation(\"Handled {CommandType}\", typeof(TCommand).Name);\n        return response;\n    }\n}\n```\n\n## 📜 License\n\nDom.Mediator is [MIT licensed](LICENSE).\n\n## 👤 Author\n\nMade with ❤️ by [André Dominic Santacroce](https://www.andresantacroce.com)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasantacroce%2Fdom.mediator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasantacroce%2Fdom.mediator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasantacroce%2Fdom.mediator/lists"}