{"id":13629493,"url":"https://github.com/SzymonHalucha/Minerals.AutoCQRS","last_synced_at":"2025-04-17T09:34:06.741Z","repository":{"id":240402586,"uuid":"802382731","full_name":"SzymonHalucha/Minerals.AutoCQRS","owner":"SzymonHalucha","description":"Simple NuGet package that provides interfaces for implementing the CQRS pattern along with automatic dependency injection and no MediatR package overhead","archived":false,"fork":false,"pushed_at":"2024-06-01T07:01:39.000Z","size":103,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-07-20T11:32:09.030Z","etag":null,"topics":["cqrs","cqrs-pattern","csharp","csharp-sourcegenerator","dependency-injection","dotnet","roslyn"],"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/SzymonHalucha.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}},"created_at":"2024-05-18T06:27:16.000Z","updated_at":"2024-08-01T22:36:46.645Z","dependencies_parsed_at":"2024-05-18T16:32:12.432Z","dependency_job_id":"2515a8d6-6338-4e4a-8d8c-554ac784067f","html_url":"https://github.com/SzymonHalucha/Minerals.AutoCQRS","commit_stats":null,"previous_names":["szymonhalucha/minerals.autocqrs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SzymonHalucha%2FMinerals.AutoCQRS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SzymonHalucha%2FMinerals.AutoCQRS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SzymonHalucha%2FMinerals.AutoCQRS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SzymonHalucha%2FMinerals.AutoCQRS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SzymonHalucha","download_url":"https://codeload.github.com/SzymonHalucha/Minerals.AutoCQRS/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223751147,"owners_count":17196580,"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":["cqrs","cqrs-pattern","csharp","csharp-sourcegenerator","dependency-injection","dotnet","roslyn"],"created_at":"2024-08-01T22:01:12.028Z","updated_at":"2024-11-08T20:31:00.801Z","avatar_url":"https://github.com/SzymonHalucha.png","language":"C#","funding_links":[],"categories":["Contributors Welcome for those","Source Generators"],"sub_categories":["1. [ThisAssembly](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ThisAssembly) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category","Patterns"],"readme":"# Minerals.AutoCQRS\n\n![GitHub License](https://img.shields.io/github/license/SzymonHalucha/Minerals.AutoCQRS?style=for-the-badge)\n![NuGet Version](https://img.shields.io/nuget/v/Minerals.AutoCQRS?style=for-the-badge)\n![NuGet Downloads](https://img.shields.io/nuget/dt/Minerals.AutoCQRS?style=for-the-badge)\n\n[Package on nuget.org](https://www.nuget.org/packages/Minerals.AutoCQRS/)\n\nThis NuGet package offers a lightweight and efficient way to implement the CQRS pattern in ASP.NET Core applications. It focuses on providing basic interfaces for commands, queries and pipelines, along with automatic dependency injection, without introducing the overhead of a mediator library such as MediatR.\n\n## Features\n\n- **Reduced boilerplate:** Package has dedicated interfaces for commands and queries, you don't need to write additional intermediate interfaces for code readability.\n- **Pipelines:** Package provides easy to use pipelines for concrete commands and queries.\n- **Automatic Dependency Injection:** Package provides automatic registration of all classes that implements *ICommandHandler*, *IQueryHandler*, *ICommandPipeline* or *IQueryPipeline* interfaces.\n- **Performance:** Package does not use System.Reflection at all, dependency injection is resolved at compile time.\n- **Compatible with .NET Standard 2.0 and C# 7.3+:** Works on a wide range of platforms and development environments.\n\n## Installation\n\nAdd the Minerals.AutoCQRS nuget package to your C# project using the following methods:\n\n### 1. Project file definition\n\n```xml\n\u003cPackageReference Include=\"Minerals.AutoCQRS\" Version=\"0.3.0\" /\u003e\n```\n\n### 2. dotnet command\n\n```bat\ndotnet add package Minerals.AutoCQRS\n```\n\n## Usage\n\nThe examples below shows how to use the package and its components.\n\n### ICommandHandler and IQueryHandler\n\nExample implementation of command and query along with their handlers.\n\n```csharp\nnamespace Minerals.Examples\n{\n    public class ExampleCommand : Minerals.AutoCQRS.Interfaces.ICommand\n    {\n        // ...\n    }\n\n    public class ExampleQuery : Minerals.AutoCQRS.Interfaces.IQuery\n    {\n        // ...\n    }\n\n    public class ExampleCommandHandler : Minerals.AutoCQRS.Interfaces.ICommandHandler\u003cExampleCommand, int\u003e\n    {\n        public Task\u003cint\u003e Handle(ExampleCommand command, CancellationToken cancellation = default)\n        {\n            // ...\n        }\n    }\n\n    public class ExampleQueryHandler : Minerals.AutoCQRS.Interfaces.IQueryHandler\u003cExampleQuery, int\u003e\n    {\n        public Task\u003cint\u003e Handle(ExampleQuery query, CancellationToken cancellation = default)\n        {\n            // ...\n        }\n    }\n}\n```\n\n### Dependency Registration\n\nBy default, dependencies are registered as Singleton.\n\n```csharp\n// Adding Handlers\nbuilder.Services.AddAutoCQRSHandlers();\n\n// Adding Pipelines\nbuilder.Services.AddAutoCQRSPipelines();\n\n// or\n\n// You can set your own policy for dependency injection\nbuilder.Services.AddAutoCQRSHandlers((collection, serviceInterfaceType, serviceConcreteType) =\u003e collection.AddScoped(serviceInterfaceType, serviceConcreteType));\n\nbuilder.Services.AddAutoCQRSPipelines((collection, serviceInterfaceType, serviceConcreteType) =\u003e collection.AddScoped(serviceInterfaceType, serviceConcreteType));\n\n```\n\n### Pipelines\n\nBelow is an example of a pipeline configuration for a command with three handlers. A Class which implements the ``ICommandPipeline`` or ``IQueryPipeline`` interface must have the ``partial`` modifier.\n\n```csharp\n    public class TestCommand : ICommand\n    {\n        // ...\n    }\n\n    public class TestCommandHandler1 : ICommandHandler\u003cTestCommand, string\u003e\n    {\n        // ...\n    }\n\n    public class TestCommandHandler2 : ICommandHandler\u003cTestCommand, string\u003e\n    {\n        // ...\n    }\n\n    public class TestCommandHandler3 : ICommandHandler\u003cTestCommand, string\u003e\n    {\n        // ...\n    }\n\n    // That's all you need to create a pipeline for the selected command or query\n    // Pipelines interfaces have overloads up to 8 handlers\n    public partial class TestCommandPipeline : ICommandPipeline\u003cTestCommand, string, TestCommandHandler1, TestCommandHandler2, TestCommandHandler3\u003e;\n```\n\n### Dispatching\n\nIf one command or query has multiple handlers the last handler will be executed and returned.\n\n```csharp\n// Dispatching selected command (ICommandDispatcher)\nstring result = await _commandDispatcher.Dispatch\u003cTestCommand, string\u003e(new TestCommand());\n\n// Dispatching selected query (IQueryDispatcher)\nstring result = await _queryDispatcher.Dispatch\u003cTestQuery, string\u003e(new TestQuery());\n\n// Dispatching selected command pipeline (ICommandPipelineDispatcher)\nIReadOnlyList\u003cstring\u003e results = await _commandPipelineDispatcher.Dispatch\u003cTestCommand, string\u003e(new TestCommand());\n\n// Dispatching selected query pipeline (IQueryPipelineDispatcher)\nIReadOnlyList\u003cstring\u003e results = await _queryPipelineDispatcher.Dispatch\u003cTestQuery, string\u003e(new TestQuery());\n```\n\n### Custom Dispatchers\n\nYou can write your own implementation of a command, query or pipeline dispatcher using the appropriate interface, ``ICommandDispatcher``, ``IQueryDispatcher``, ``ICommandPipelineDispatcher`` or ``IQueryPipelineDispatcher``.\n\n```csharp\npublic class CustomCommandDispatcher : ICommandDispatcher\n{\n    public Task\u003cTResult\u003e Dispatch\u003cTCommand, TResult\u003e(TCommand command, CancellationToken cancellation = default)\n        where TCommand : ICommand, new()\n        where TResult : notnull\n    {\n        // ...\n    }\n}\n\n// or\n\npublic class CommandPipelineDispatcher : ICommandPipelineDispatcher\n{\n    public async Task\u003cIReadOnlyList\u003cTResult\u003e\u003e Dispatch\u003cTCommand, TResult\u003e(TCommand command, CancellationToken cancellation = default)\n        where TCommand : ICommand, new()\n        where TResult : notnull\n    {\n        // ...\n    }\n}\n```\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [branches on this repository](https://github.com/SzymonHalucha/Minerals.AutoCQRS/branches).\n\n## Authors\n\n- **Szymon Hałucha** - Maintainer\n\nSee also the list of [contributors](https://github.com/SzymonHalucha/Minerals.AutoCQRS/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSzymonHalucha%2FMinerals.AutoCQRS","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSzymonHalucha%2FMinerals.AutoCQRS","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSzymonHalucha%2FMinerals.AutoCQRS/lists"}