0
votes

This is more of a design question so apologies if this is in the wrong place. That said, I am designing an application which comprises of a WPF user interface with a WCF service layer that provides access to the application data and business logic. I have several scenarios where CQRS and ES are required which is where my question comes from.

CQRS is about Command and Query separation, so the question I have is should my WCF service also be separated so I have the Command methods in one service and the Query methods in another. For example:

public class PatientCommandService
{
    public void AddPatient(AddPatientDto patient) { }
}

public class PatientQueryService
{
    public PatientDto GetById(int id) { }
}

I am new to CQRS and ES and have struggled to find anything tangible on the internet that would answer this question, particularly around web services such as WCF and WebAPI.

It seem sensible to have all service methods within the same service and separate the Command and Query through a repository layer in the implementation of each service method. But that seems to defy the separation part of CQRS and I am also conflicted with SOLID principles around Single Responsibility.

Has anyone implemented CQRS behind a WCF service and dealt with this scenario, I am seeking some advice really about the best approach for implementing CQRS.

1

1 Answers

2
votes

CQRS is not about Command/Query separation but about responsibility segregation. With CQRS your database isn't ACID anymore, it's more of a eventual consistency approach.

The reason is as the read/write code is separated it also means that the read model have to be populated using events from the write model.

Your write transaction -> change event is published -> read model updates it's data

I strongly suggest that you move to a task based approach when it comes to your UI. A command should wrap an business transaction instead of a database operation. What I mean is that a command typically involves more than one root aggregate.

If that doesn't work for you, just use an audit table instead of introducing all the complexity that comes with CQRS.