Skip to content

steentottrup/SimpleCQS

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleCQS Build status

Library for simple command query separation

NuGet

Install-Package SimpleCQS

Simple Example with Autofac

Install-Package SimpleCQS.Autofac
Commands and Handlers and Validators
public class MyCommand : ICommand
{
  public string CommandProp1 { get; set; }
  public int CommandProp2 { get; set; }
  //(...)
}
  
public class MyCommandHandler : ICommandHandler<MyCommand>
{
  public MyCommandHandler( /* dependencies */)
  {
  }

  public void Handle(MyCommand command)
  {
    //do something with command
  }
}

public class MyCommandValidator : AbstractValidator<MyCommand>
{
  public MyCommandValidator()
  {
    RuleFor(x => x.CommandProp1)
      .NotEmpty();

    RuleFor(x => x.CommandProp2)
      .GreaterThan(0);

    //(...)
  }
}
Autofac configuration
var builder = new ContainerBuilder();
builder.RegisterSimpleCQS(AppDomain.CurrentDomain.GetAssemblies()); //Assemblies with handlers or validators
var container = builder.Build();
Usage
var commandBus = container.Resolve<ICommandExecutor>(); //Executor with validation result
//var commandBus = container.Resolve<ICommandDispatcher>(); //Dispather with validation
//var commandBus = container.ResolveNamed<ICommandDispatcher>("SimpleDispatcher") //Dispather without validation;

var command = new MyCommand()
{
  CommandProp1 = "Prop1",
  CommandProp2 = 1
};

var validationResult = commandBus.Execute(command) //Executor with validation result;
//commandBus.Dispatch(command); //Dispatcher with and without validation

About

Library for simple command query separation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%