{"id":25805639,"url":"https://github.com/Prognetics/Prognetics.CQRS","last_synced_at":"2025-02-27T19:29:04.586Z","repository":{"id":64211756,"uuid":"574132111","full_name":"Prognetics/Prognetics.CQRS","owner":"Prognetics","description":"We would like to share with the community our companies production verified mediator pattern based CQRS library.","archived":false,"fork":false,"pushed_at":"2023-05-07T14:00:36.000Z","size":87,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-20T18:48:06.959Z","etag":null,"topics":["cqrs","csharp","dotnet"],"latest_commit_sha":null,"homepage":"https://prognetics.com","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/Prognetics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-04T14:27:12.000Z","updated_at":"2024-01-21T15:56:48.000Z","dependencies_parsed_at":"2023-02-19T00:15:45.498Z","dependency_job_id":null,"html_url":"https://github.com/Prognetics/Prognetics.CQRS","commit_stats":null,"previous_names":["chrisgawlinski/prognetics.cqrs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prognetics%2FPrognetics.CQRS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prognetics%2FPrognetics.CQRS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prognetics%2FPrognetics.CQRS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prognetics%2FPrognetics.CQRS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Prognetics","download_url":"https://codeload.github.com/Prognetics/Prognetics.CQRS/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241050559,"owners_count":19900656,"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","csharp","dotnet"],"created_at":"2025-02-27T19:29:03.563Z","updated_at":"2025-02-27T19:29:04.579Z","avatar_url":"https://github.com/Prognetics.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Welcome to Prognetics CQRS!\n\nWe would like to share with the community our companies production verified mediator pattern based CQRS library.\n\n## **How it works?**\n\nThrought the Mediator object you are able to issue different kinds of handlers to be called.\n\nFirst are commands:\n```c#\nvoid Send\u003cTCommand\u003e(TCommand command) where TCommand : ICommand;\n\nTask SendAsync\u003cTCommand\u003e(TCommand command) where TCommand : ICommand;\n```\nThey allow you to run a logic that is supposed to modify the state of the application. They do not return a value.\n\nSecond are queries:\n```c#\nTResult Fetch\u003cTQuery, TResult\u003e(TQuery query) where TQuery :  IQuery\u003cTResult\u003e;\n\nTask\u003cTResult\u003e FetchAsync\u003cTQuery, TResult\u003e(TQuery query) where TQuery : IQuery\u003cTResult\u003e;\n```\nThey are used to return values, and should not perform any state modification operations.\n\n\nThird are events:\n```c#\nTask Publish\u003cTEvent\u003e(TEvent @event) where TEvent : IEvent;\n```\nWhile each query or command can only have a single synchronous and asynchronous handler, this is not the case for events. When an event is published, the mediator will run all the handlers that are registered to handle it.\n\n## **Setup**\nWe prepared two integrations for your comfort. Depending on which DI continer you would like to use, please pick one of them or download base 'Prognetics.CQRS' package and implement your own integration!\n\nThe library `Prognetics.CQRS.Autofac` provides an easy-to-use extension for integration with Autofac. To register handler implementations, it requires a collection of assemblies to be scanned:\n\n```c#\nbuilder.RegisterProgenticsCQRSModule(Assembly.GetExecutingAssembly());\n```\n\nThe framework can also be integreted with Microsoft Dependency Injection. Install `Prognetics.CQRS.MicrosoftDI` and add to ths service collection:\n\n```c#\nservices.AddProgneticsCQRS(Assembly.GetExecutingAssembly());\n```\n\n**However, unlike Autofac, it does not support the use of generic handlers, so these will be skipped if they are defined.**\n\n\nThe library can be used with other/without dependency injection. Install `Prognetics.CQRS` package and define the way of resolving handlers in your application by implementing the `Prognetics.CQRS.IHandlerResolver` interface and pass the implementation to `Prognetics.CQRS.Mediator`. The mediator will then be ready to work.\n\n## **Defining Queries, Commands and Events**\n\n### **Query**\nThe query must implement the `IQuery\u003cTResult\u003e` interface, where TResult is the type of the expected result:\n\n```c#\npublic record MyQuery(string Data) : IQuery\u003cstring\u003e\n```\n\n You can implement the query handler in two ways:\n\n - **Synchronously** by implementing the `IQueryHandler\u003cTQuery, TResult\u003e` interface\n\n```c#\npublic class MyQueryHandler : IQueryHandler\u003cMyQuery, string\u003e\n{\n    public string Handle(MyQuery query)\n    {\n        // Process the query\n    }\n}\n```\n\n - **Asynchronously** by implementing the `IAsyncQueryHandler\u003cTQuery, TResult\u003e` interface\n\n```c#\npublic class MyQueryHandler : IAsyncQueryHandler\u003cMyQuery, string\u003e\n{\n    public async Task\u003cstring\u003e Handle(MyQuery query)\n    {\n        // Process the query\n        // await sth\n    }\n}\n```\n\nwhere `TQuery` is the type of your query and `TResult` is the type of the result specified in the `IQuery\u003cTResult\u003e` interface.\n\n\n### **Command**\nThe command must implement the `ICommand` interface:\n\n```c#\npublic record MyCommand(string Data) : ICommand\n```\n\nCommand handler can be:\n - **Synchronous** by implementing the `ICommandHandler\u003cTCommand\u003e` interface\n\n```c#\npublic class SumCommandHandler : ICommandHandler\u003cMyCommand\u003e\n{\n    public void Handle(MyCommand command)\n    {\n        // Process the command\n    }\n}\n```\n\n - **Asynchronously** by implementing the `IAsyncCommandHandler\u003cTCommand\u003e` interface\n\n```c#\npublic class SumCommandHandler : IAsyncCommandHandler\u003cMyCommand\u003e\n{\n    public async Task Handle(MyCommand command)\n    {\n        // Process the command\n        // await sth\n    }\n}\n```\nwhere `TCommand` is the type of your command\n\n**NOTE: You can define both an asynchronous and synchronous handler for the same query or command**\n\n### **Event**\nThe event must implement the `IEvent` interface.\n\n```c#\npublic record MyEvent(string Data) : IEvent\n```\n\nEvent handler can must be defined by implementing the `IEventHandler\u003cTEvent\u003e` interface:\n```c#\npublic class MyEventHandler : IEventHandler\u003cMyEvent\u003e\n{\n    public async Task Handle(MyEvent @event)\n    {\n        // Process the event\n        // await sth\n    }\n}\n```\n where `TEvent` is the type of your event.\n\n\n\n## Running Tests\n\nThe tests project is based on xunit with visual studio runner. To run right-click the project file and select \"Run Tests\".\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPrognetics%2FPrognetics.CQRS","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPrognetics%2FPrognetics.CQRS","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPrognetics%2FPrognetics.CQRS/lists"}