{"id":22011093,"url":"https://github.com/leanwit/dotnet-cqrs","last_synced_at":"2025-05-06T19:07:02.133Z","repository":{"id":45368257,"uuid":"261043865","full_name":"Leanwit/dotnet-cqrs","owner":"Leanwit","description":"A CQRS Project using a DDD structure without MediatR library","archived":false,"fork":false,"pushed_at":"2023-01-31T12:43:02.000Z","size":64,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2023-08-04T09:06:44.273Z","etag":null,"topics":["cqrs","csharp","dotnet-cqrs"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Leanwit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-03T23:57:12.000Z","updated_at":"2023-06-08T07:33:34.000Z","dependencies_parsed_at":"2023-01-25T14:00:45.765Z","dependency_job_id":null,"html_url":"https://github.com/Leanwit/dotnet-cqrs","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leanwit%2Fdotnet-cqrs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leanwit%2Fdotnet-cqrs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leanwit%2Fdotnet-cqrs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leanwit%2Fdotnet-cqrs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Leanwit","download_url":"https://codeload.github.com/Leanwit/dotnet-cqrs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227254020,"owners_count":17754198,"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-cqrs"],"created_at":"2024-11-30T02:15:57.433Z","updated_at":"2024-11-30T02:15:58.059Z","avatar_url":"https://github.com/Leanwit.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dotnet-cqrs\n\nThis project shows a clean way to use CQRS without using the MediatR library.\n\nIn C# is common to use a library named [MediatR](https://github.com/jbogard/MediatR) to implement CQRS. This is an amazing library but forces you to implement the interface INotification, INotificationHandler\u003cT\u003e and IRequestHandler\u003cT1,T2\u003e in your domain/application layer coupling this with an infrastructure library.\nThis is a different approach to avoid add this coupling.\n\n## Commands\n\n### A command example\n\n```csharp\npublic class CreateItemCommand : Command\n{    \n    public CreateItemCommand(Guid id, string name) \n    {\n        Id = id;\n        Name = name;\n    }\n}\n```\n\n### A handler example\n\n```csharp\npublic class CreateItemCommandHandler : CommandHandler\u003cCreateItemCommand\u003e\n{\n    private readonly ItemRepository _repository;\n\n    public CreateItemCommandHandler(ItemRepository repository)\n    {\n        _repository = repository;\n    }\n\n    public async Task Handle(CreateItemCommand command)\n    {\n        await _repository.Add(new Item(command.Id, command.Name));\n    }\n}\n```\n\n### Interfaces to add in Domain Layer\n\n[Command Interfaces](https://github.com/Leanwit/dotnet-cqrs/tree/master/Src/CQRS.Shared/Domain/Bus/Command)\n\n## Queries\n\n### A query example:\n\n```csharp\npublic class FindItemQuery : Query\n{\n    public Guid Id { get; private set; }\n\n    public FindItemQuery(Guid id)\n    {\n        Id = id;\n    }\n}\n```\n\n### A handler example\n\n```csharp\npublic class FindItemQueryHandler : QueryHandler\u003cFindItemQuery, ItemResponse\u003e\n{\n    private readonly ItemRepository _repository;\n\n    public FindItemQueryHandler(ItemRepository repository)\n    {\n        _repository = repository;\n    }\n\n    public async Task\u003cItemResponse\u003e Handle(FindItemQuery query)\n    {\n        Item item = await _repository.GetById(query.Id);\n        \n        return new ItemResponse(item.Id, item.Name, item.IsCompleted);\n    }\n}\n```\n\n### Interfaces to add in Domain Layer\n\n[Query Interfaces](https://github.com/Leanwit/dotnet-cqrs/tree/master/Src/CQRS.Shared/Domain/Bus/Query)\n\n## InMemoryBus implementation\n\n[InMemoryCommandBus](https://github.com/Leanwit/dotnet-cqrs/blob/master/Src/CQRS.Shared/Infrastructure/Bus/Command/InMemoryCommandBus.cs)\n\n[InMemoryQueryBus](https://github.com/Leanwit/dotnet-cqrs/blob/master/Src/CQRS.Shared/Infrastructure/Bus/Query/InMemoryQueryBus.cs)\n\n## Dependency Injection\n\n### Command\n\n```csharp\nservices.AddScoped\u003cCommandHandler\u003cCreateItemCommand\u003e, CreateItemCommandHandler\u003e();\n```\n\n### Query\n\n```csharp\nservices.AddScoped\u003cQueryHandler\u003cFindItemQuery, ItemResponse\u003e, FindItemQueryHandler\u003e();\n```\n\n### Automatic Load\n\n```csharp\nservices.AddCommandServices(typeof(Command).Assembly);\nservices.AddQueryServices(typeof(Query).Assembly);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleanwit%2Fdotnet-cqrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleanwit%2Fdotnet-cqrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleanwit%2Fdotnet-cqrs/lists"}