Skip to content

Releases: softawaregmbh/library-cqs

CQS 4.0

22 Aug 09:16
c144858
Compare
Choose a tag to compare

Breaking Changes

  • There is now an interface ICommand<TResult> for commands that return values. While this should be used sparingly, there are some cases where it can be useful.
  • ICommand (which should be the default for implementing commands) derives from this new ICommand<NoResult> interface.
  • There is now a common base interface for IQuery<TResult> and ICommand<TResult> (and thus ICommand): IRequest<TResult. This has the following advantages:
    • There is no need to distinguish between IQueryHandler<TResult> and ICommandHandler anymore. Simply use IRequestHandler<TResult>.
    • For cross-cutting concerns, you can write decorators that target IRequestHandler<TResult>. Before you had to write one for IQueryHandler<TResult> and one for ICommandHandler.
    • Instead of IQueryProcessor and ICommandProcessor, you can simply use IRequestProcessor. ExecuteAsync has been renamed to HandleAsync.
  • The cancellation token is now a required parameter for the HandleAsync method.
Show detailed upgrade instructions
  • Update all softaware.CQS packages to version 4.0.0 or higher

  • Replace IQueryHandler<TQuery, TResult> with IRequestHandler<TQuery, TResult>:

    • Replace in files (Use regular expression)
      IQueryHandler<(.*?), (.*?)>
      IRequestHandler<$1, $2>
  • Replace ICommandHandler<TCommand> with IRequestHandler<TCommand, NoResult>

    • Replace
      ICommandHandler<(.*?)>
      IRequestHandler<$1, NoResult>
  • Replace query handler HandleAsync interface implementation: Add CancellationToken

    • Replace
      Task<(.+?)> HandleAsync\(([^,]+?) ([^,]+?)\)
      Task<$1> HandleAsync($2 $3, System.Threading.CancellationToken cancellationToken)
  • Replace command handler HandleAsync: add NoResult and CancellationToken

    • Replace
      Task HandleAsync\(([^,]+?) ([^,]+?)\)
      Task<NoResult> HandleAsync($1 $2, System.Threading.CancellationToken cancellationToken)
  • Remove HandleAsync overloads delegating to CancellationToken version

    • Replace with empty string (You might need to adjust the expressions based on your formatting):
      Task<(.+?)> HandleAsync\(([^,]+?) ([^,]+?)\) =>
    • Replace with empty string
      public  this.HandleAsync(query, default);
  • Replace IQueryProcessor and ICommandProcessor with IRequestProcessor

    • Replace IQueryProcessor with IRequestProcessor
    • Replace ICommandProcessor with IRequestProcessor
    • Replace queryProcessor with requestProcessor
    • Replace commandProcessor with requestProcessor
    • Replace
      requestProcessor.ExecuteAsync\(([^,]+?)\);
      requestProcessor.HandleAsync($1, cancellationToken);
    • Remove duplicates where IQueryProcessor and ICommandProcessor were injected
  • Add return NoResult.Value to command handlers

  • Optional: Add CancellationToken to Controller actions

    • Replace with file pattern: *Controller.cs

    • With parameters:

      public async (.+)\((.+)\)
      public async $1($2, System.Threading.CancellationToken cancellationToken)
      • Without parameters:
      public async (.+)\(\)
      public async $1(System.Threading.CancellationToken cancellationToken)
  • Add missing CancellationToken parameters

  • Decorators: Refactor command handler decorators to 2 generic type parameters

  • Replace AddQueryHandlerDecorator and AddCommandHandlerDecorator with AddRequestHandlerDecorator

  • Remove PublicQueryHandlerDecorator and PublicCommandHandlerDecorator if you referenced them explicitely.

  • Optional: Combine duplicate decorators implementing IQueryHandler<TResult> and ICommandHandler into a single class implementing IRequestHandler

  • Optional: Use ICommand<TResult> instead of ICommand if you used some workarounds for returning values from commands (like setting a property on the command)

Simple Injector v5

10 Sep 18:45
Compare
Choose a tag to compare

softaware.Cqs.SimpleInjector

3.0.0

Breaking Changes

  • Major update of Simple Injector to version 5.

  • If you are using the NuGet package softaware.Cqs.Decorators.UsageAware, the types UsageAwareCommandLogger<> and UsageAwareQueryLogger<,> must now be registered in the container, since these classes won't be resolved automatically in the new Simple Injector version any more by default. For more information, see https://simpleinjector.org/ructd.

    this.container.Register(typeof(UsageAwareCommandLogger<>));
    this.container.Register(typeof(UsageAwareQueryLogger<,>));

2.1.0

02 Mar 07:44
58bd171
Compare
Choose a tag to compare

New Features

Added new NuGet package softaware.Cqs.Decorators.FluentValidation which supports command and query decorators for using FluentValidation.

2.0.2

12 Feb 07:38
Compare
Choose a tag to compare

Bug Fixes

  • The CancellationToken will now correctly be passed to the inner handlers when using the Transaction-, Validation- or UsageAware decorators.

2.0.1

17 Dec 12:25
Compare
Choose a tag to compare
  • XML documentation for all public types has been added.

2.0.0

17 Dec 12:25
Compare
Choose a tag to compare

Breaking Changes

  • All packages now target netstandard2.1.
  • It is now needed that the two decorators softaware.Cqs.SimpleInjector.PublicCommandHandlerDecorator and softaware.Cqs.SimpleInjector.PublicQueryHandlerDecorator are registered as last decorator in the chain when using softaware.Cqs.SimpleInjector.DynamicCommandProcessor and softaware.Cqs.SimpleInjector.DynamicQueryProcessor. This is needed so that the dynamic processors can call the correct overload of the HandleAsync method. Secondly this is needed when trying to call an internal decorator or an internal handler. If these two decorators are not registered, an exception will be thrown when trying to call ExecuteAsync on either the ICommandProcessor or IQueryProcessor. See here for more details.
  • The package softaware.Cqs.EntityFramework is deprecated and no longer supported. It has been removed from this release.
  • The constructor parameter of softaware.Cqs.Decorators.Validation.DataAnnotationsValidator has been removed as it's not needed.

New Features

  • It is now possible to pass a CancellationToken when executing command handlers and query handlers. So it is now easily possible to cancel the execution of commands and queries. To use the cancellable version, implement the HandleAsync(command, token) default interface method and delegate to this implementation in the HandleAsync(command) method:

      internal class LongRunningCommandHandler : ICommandHandler<LongRunningCommand>
      {
          public Task HandleAsync(LongRunningCommand command)
          {
              return this.HandleAsync(command, default);
          }
    
          public async Task HandleAsync(LongRunningCommand command, CancellationToken cancellationToken)
          {
              await Task.Delay(TimeSpan.FromSeconds(30), cancellationToken);
          }
      }

    Note: For this to work, all existing Decorators must override the HandleAsync(command, token) method and pass the cancellationToken to the inner handlers.

  • Unit tests have been added.

2.0.0-beta

13 Dec 10:46
Compare
Choose a tag to compare
2.0.0-beta Pre-release
Pre-release

Breaking Changes

  • All packages now target netstandard2.1.
  • It is now needed that the two decorators softaware.Cqs.SimpleInjector.PublicCommandHandlerDecorator and softaware.Cqs.SimpleInjector.PublicQueryHandlerDecorator are registered as last decorator in the chain when using softaware.Cqs.SimpleInjector.DynamicCommandProcessor and softaware.Cqs.SimpleInjector.DynamicQueryProcessor. This is needed so that the dynamic processors can call the correct overload of the HandleAsync method. Secondly this is needed when trying to call an internal decorator or an internal handler. If these two decorators are not registered, an exception will be thrown when trying to call ExecuteAsync on either the ICommandProcessor or IQueryProcessor. See here for more details.
  • The package softaware.Cqs.EntityFramework is deprecated and no longer supported. It has been removed from this release.

New Features

  • It is now possible to pass a CancellationToken when executing command handlers and query handlers. So it is now easily possible to cancel the execution of commands and queries. To use the cancellable version, implement the HandleAsync(command, token) default interface method and delegate to this implementation in the HandleAsync(command) method:

      internal class LongRunningCommandHandler : ICommandHandler<LongRunningCommand>
      {
          public Task HandleAsync(LongRunningCommand command)
          {
              return this.HandleAsync(command, default);
          }
    
          public async Task HandleAsync(LongRunningCommand command, CancellationToken cancellationToken)
          {
              await Task.Delay(TimeSpan.FromSeconds(30), cancellationToken);
          }
      }

    Note: For this to work, all existing Decorators must override the HandleAsync(command, token) method and pass the cancellationToken to the inner handlers.

1.1.1

05 Nov 14:13
Compare
Choose a tag to compare

SourceLink support

1.0.1

24 Sep 08:05
Compare
Choose a tag to compare

Updated NuGet package metadata

1.0.0

18 Sep 18:22
Compare
Choose a tag to compare

Initial release