dotnet-cqrs/README.md

68 lines
4.7 KiB
Markdown
Raw Normal View History

# CQRS
Our implementation of query and command responsability segregation (CQRS).
## Getting Started
> Install nuget package to your awesome project.
| Full Version | NuGet | NuGet Install |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -----------------------------------------------------: |
| PoweredSoft.CQRS.Abstractions | <a href="https://www.nuget.org/packages/PoweredSoft.CQRS.Abstractions/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.CQRS.Abstractions.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.CQRS.Asbtractions/)</a> | ```PM> Install-Package PoweredSoft.CQRS.Abstractions ``` |
| PoweredSoft.CQRS | <a href="https://www.nuget.org/packages/PoweredSoft.CQRS/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.CQRS.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.CQRS/)</a> | ```PM> Install-Package PoweredSoft.CQRS ``` |
2021-08-11 17:05:56 -04:00
| PoweredSoft.CQRS.FluentValidation | <a href="https://www.nuget.org/packages/PoweredSoft.CQRS.FluentValidation/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.CQRS.FluentValidation.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.CQRS.FluentValidation/)</a> | ```PM> Install-Package PoweredSoft.CQRS.FluentValidation ``` |
| PoweredSoft.CQRS.AspNetCore.Abstractions | <a href="https://www.nuget.org/packages/PoweredSoft.CQRS.AspNetCore.Abstractions/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.CQRS.AspNetCore.Abstractions.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.CQRS.AspNetCore.Abstractions/)</a> | ```PM> Install-Package PoweredSoft.CQRS.AspNetCore.Abstractions ``` |
2021-02-02 12:41:38 -05:00
| PoweredSoft.CQRS.AspNetCore | <a href="https://www.nuget.org/packages/PoweredSoft.CQRS.AspNetCore/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.CQRS.AspNetCore.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.CQRS.AspNetCore/)</a> | ```PM> Install-Package PoweredSoft.CQRS.AspNetCore ``` |
2021-08-11 17:05:56 -04:00
| PoweredSoft.CQRS.GraphQL.HotChocolate | <a href="https://www.nuget.org/packages/PoweredSoft.CQRS.GraphQL.HotChocolate/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.CQRS.GraphQL.HotChocolate.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.CQRS.GraphQL.HotChocolate/)</a> | ```PM> Install-Package PoweredSoft.CQRS.GraphQL.HotChocolate ``` |
2021-02-02 12:41:38 -05:00
## Sample of startup code for aspnetcore MVC
```csharp
public void ConfigureServices(IServiceCollection services)
{
// make sure to add your queries and commands before the .AddPoweredSoftQueries and .AddPoweredSoftCommands
AddQueries(services);
AddCommands(services);
// adds the non related to aspnet core features.
services.AddPoweredSoftCQRS();
services
.AddControllers()
.AddPoweredSoftQueries() // adds queries to aspnetcore mvc.(you can make it configurable to load balance only commands on a instance)
.AddPoweredSoftCommands() // adds commands to aspnetcore mvc. (you can make it configurable to load balance only commands on a instance)
.AddFluentValidation();
2021-08-11 17:05:56 -04:00
// enabling gql.
services
.AddGraphQLServer()
.AddProjections()
.AddQueryType(d => d.Name("Query"))
.AddPoweredSoftQueries()
.AddPoweredSoftDynamicQueries()
.AddMutationType(d => d.Name("Mutation"))
.AddPoweredSoftMutations();
2021-02-02 12:41:38 -05:00
services.AddSwaggerGen();
}
```
2021-02-02 12:42:44 -05:00
> Example how to add your queries and commands.
```csharp
private void AddCommands(IServiceCollection services)
{
services.AddCommand<CreatePersonCommand, CreatePersonCommandHandler>();
services.AddTransient<IValidator<CreatePersonCommand>, CreatePersonCommandValidator>();
services.AddCommand<EchoCommand, string, EchoCommandHandler>();
services.AddTransient<IValidator<EchoCommand>, EchoCommandValidator>();
}
private void AddQueries(IServiceCollection services)
{
services.AddQuery<PersonQuery, IQueryable<Person>, PersonQueryHandler>();
}
```
2021-02-02 12:41:38 -05:00