Demo | ||
PoweredSoft.CQRS | ||
PoweredSoft.CQRS.Abstractions | ||
PoweredSoft.CQRS.AspNetCore | ||
PoweredSoft.CQRS.AspNetCore.Abstractions | ||
PoweredSoft.CQRS.AspNetCore.OData | ||
PoweredSoft.CQRS.AspNetCore.OData.Abstractions | ||
PoweredSoft.CQRS.DynamicQuery | ||
PoweredSoft.CQRS.DynamicQuery.Abstractions | ||
PoweredSoft.CQRS.DynamicQuery.AspNetCore | ||
PoweredSoft.CQRS.FluentValidation | ||
PoweredSoft.CQRS.GraphQL.Abstractions | ||
PoweredSoft.CQRS.GraphQL.DynamicQuery | ||
PoweredSoft.CQRS.GraphQL.FluentValidation | ||
PoweredSoft.CQRS.GraphQL.HotChocolate | ||
PoweredSoft.CQRS.GraphQL.HotChocolate.DynamicQuery | ||
.gitattributes | ||
.gitignore | ||
azure-pipeline.yaml | ||
LICENSE | ||
PoweredSoft.CQRS.sln | ||
README.md |
CQRS
Our implementation of query and command responsability segregation (CQRS).
Getting Started
Install nuget package to your awesome project.
Sample of startup code for aspnetcore MVC
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();
// enabling gql.
services
.AddGraphQLServer()
.AddProjections()
.AddQueryType(d => d.Name("Query"))
.AddPoweredSoftQueries()
.AddPoweredSoftDynamicQueries()
.AddMutationType(d => d.Name("Mutation"))
.AddPoweredSoftMutations();
services.AddSwaggerGen();
}
Example how to add your queries and commands.
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>();
}
Fluent Validation
We use fluent validation in all of our projects, but we don't want it to be enforced.
If you install. PoweredSoft.CQRS.FluentValidation
you can use this way of registrating your commands.
// without Package.
services.AddCommand<EchoCommand, string, EchoCommandHandler>();
services.AddTransient<IValidator<EchoCommand>, EchoCommandValidator>();*/
// with PoweredSoft.CQRS.FluentValidation package.
services.AddCommandWithValidator<EchoCommand, string, EchoCommandHandler, EchoCommandValidator>();