Questions tagged [command-query-separation]

Command–Query Separation (CQS) is a principle of imperative computer programming. Not to be confused with Command-Query Responsibility Segregation (CQRS), a distributed design pattern derived from CQS.

Filter by
Sorted by
Tagged with
7 votes
1 answer
441 views

After `x = x.y()`, why did `x` become `None` instead of being modified (possibly causing "AttributeError: 'NoneType' object has no attribute")?

If your question was closed as a duplicate of this, it is because you have some code of the general form x = X() # later... x = x.y() # or: x.y().z() where X is some type that provides y and z ...
Karl Knechtel's user avatar
1 vote
2 answers
2k views

Is there any rule in CQRS which doesn't allow to use a query and a command in the same controller action?

For example: I want to delete an item or return 404 if it doesn't exist from a controller action. Am I breaking any rules? Commands are still separated from queries. [ApiController] public class ...
Pan Zdrowie's user avatar
0 votes
1 answer
396 views

CQS: Who is responsible for data caching and when?

When and who should be responsible for caching data into local data store from API GET requests in DDD architecture with CQS based use cases? First thing that comes to mind: Initiate a Query to get ...
Tomas Jablonskis's user avatar
1 vote
1 answer
785 views

Vertical Slice Architecture - What should go in the Controller, Command/Query, Response, CommandHandler?

After some thought and consideration, I have decided to restructure my existing directory structure of an app I have which is currently sliced Horizontally (in layers), into a Vertical Sliced approach....
Vahe's user avatar
  • 1,699
0 votes
1 answer
126 views

In CQ(R)S, is it OK to use a Command as a parameter of a model constructor?

Say I have a CreateUser command: class CreateUser { public string $email; public string $password; public string $firstName; public string $lastName; public LocalDate $dateOfBirth; ...
BenMorel's user avatar
  • 34.6k
2 votes
1 answer
513 views

CQRS and unit of work - one command for all the changes, or many commands + a save command?

In a screen that displays many order detail lines of order, users can add, update, or delete rows or columns and then click the "Save" button to save all the order changes in one transaction. Option ...
ca9163d9's user avatar
  • 27.4k
2 votes
2 answers
1k views

How to update read model in CQRS pattern on schema change of write model database?

While using CQRS pattern with domain events to generate read model. If we add new column in database with some default data or insert new row directly from sql query manually, in that case no events ...
kailashdesiti's user avatar
2 votes
1 answer
2k views

How to generate read data in CQRS from existing write database?

Currently we have an Asp.net application which uses SQL server for write and also read queries as a normal monolith application. Now we want to move to CQRS. In CQRS the read model is generated on ...
kailashdesiti's user avatar
1 vote
1 answer
66 views

Command Query Separation - Asynchronous Commands that return values

I have adopted the Command Query Separation principle in a project. However, I am not adhering to it strictly as we have a need for Commands to return values. Many people refer to this article which ...
JTech's user avatar
  • 3,420
2 votes
2 answers
196 views

What are the recomendation for developing .net core 2.2 web api for following bulleted points? [closed]

I am developing a new WebApi using .NetCore2.2, Autofac4, Dapper. There are few very basic questions because this is my first WebApi project. As part of this project I have to write both unit-test and ...
MSR's user avatar
  • 95
3 votes
3 answers
2k views

Implementation of Event-Sourcing / CQRS approach in api-platform

on official Api-Platform website there is a General Design Considerations page. Last but not least, to create Event Sourcing-based systems, a convenient approach is: to persist data in an ...
Yury Garris's user avatar
3 votes
3 answers
988 views

Single function classes (named as verbs)

I'm trying out a new code structure where I'm splitting all my giant repositories and factories into loads of smaller classes each with a single responsibility. And on top of this I'm using verbs for ...
svejk's user avatar
  • 63
2 votes
1 answer
1k views

CQS and updating an existing entity

I'm just trying to get my head around how one goes about updating an entity using CQS. Say the UI allows a user to update several properties of a particular entity, and on submit, in the back-end, an ...
CraigM's user avatar
  • 561
0 votes
2 answers
39 views

Can not implicity convert type Systems.Collection.Generic.List<feedEventViewModel> to Proj.Areas.Management.Models.FeedEventViewModel

I'm trying to convert a view model to list and then return it to the view but am getting the cannot implicity convert type error. Code: public ActionResult Index(FeedEventCommand command) { var ...
Alex's user avatar
  • 443
0 votes
1 answer
24 views

Property seems to be changing between method calls, but no code is supposed to be changing it

I have an Octet class that is suppose to "package" eight samples and then send them forward. It has methods to add a new sample, check if it is already full, and to extract a Frame datastructure built ...
heltonbiker's user avatar
  • 26.7k
1 vote
1 answer
182 views

Confusion about interaction with other domains

We're creating a new application for an entirely new domain model (and Bounded Context) 'Appointment'. We chose to combine CQS with Hexagonal Architecture (using ports and adapters) for our new domain....
user2054927's user avatar
0 votes
0 answers
769 views

CQS pattern with Spring / Hibernate

I'm developing a Java/Spring/Hibernate application that adheres to the CQS (Query Command Separation) pattern. Put simply: our domain model is only used by Commands which describe some operation ...
user2054927's user avatar
0 votes
2 answers
279 views

CQS with out parameter

In CQS (Command Query Separation) it is common to have commands with a "void" return value and Queries with a return type. (or so I have learned...) Now I wonder if this COMMAND is valid then, ...
RubenHerman's user avatar
  • 1,684
4 votes
1 answer
3k views

Separate application service for command / query in CQRS implementation in Domain Driven Design?

When implementing CQRS with Domain Driven Design, we separate our command interface from our query interface. My understanding is that at the domain level this reduces complexity significantly (...
drizzie's user avatar
  • 3,351
6 votes
2 answers
983 views

Is running a query from a command a violation of Command-Query Separation?

Given a real-world anonymous shopping cart, the "AddToCart" workflow must do the following steps: Lookup the current product from the database. Get the price from the product or use a service to ...
NightOwl888's user avatar
  • 55.7k
118 votes
5 answers
38k views

Difference between CQRS and CQS

I am learning what is CQRS pattern and came to know there is also CQS pattern. When I tried to search I found lots of diagrams and info on CQRS but didn't found much about CQS. Key point in CQRS ...
Mr punch's user avatar
  • 1,766
6 votes
3 answers
612 views

Is returning a Task violating the CQS-principle?

The CQS-principle (https://en.wikipedia.org/wiki/Command%E2%80%93query_separation) states that a command should return void. The recommendation for async methods is to never return void (https://msdn....
Emil Lundin's user avatar
2 votes
1 answer
142 views

Maintaining CQS When Tracking Number Of Queries

In my web app I'm tracking view counts on pages. Right now, the action in the controller issues a command to the data layer to increment the view count on the model before returning the result of the ...
glcheetham's user avatar
15 votes
5 answers
25k views

Event sourcing infrastructure implementation

I implement Event Sourcing and CQRS pattern in my application. I inspired by CQRS journey where I downloaded sample code. There I found whole infrastructure for Event sourcing (CommandHandlers, ...
y0j0's user avatar
  • 3,389
1 vote
2 answers
2k views

How to return result while applying Command query separation (CQS)

I am separating my query and command on service side like this: public class ProductCommandService{ void AddProduct(Product product); } public interface ProductQueryService{ Product ...
barteloma's user avatar
  • 6,423
0 votes
2 answers
291 views

Does the JDK source code violate command-query separation (CQS)?

These two snippets are from the JDK source code: public boolean remove(Object o) { if (o == null) { for (int index = 0; index < size; index++) if (elementData[index] == ...
superman's user avatar
2 votes
2 answers
2k views

How to identify if a project has used CQS OR CQRS? What is the difference between CQS and CQRS?

I might sound dumb with this question but i am really confused. Does creating a command,query,commandhanlder,queryhandler and repositories and using dependency injection to resolve queryhandlers and ...
Dilip Nandakumar's user avatar
1 vote
0 answers
100 views

Pull Parsing and CQS

I'm creating a pull parser and it relies heavily on reading characters in a sequential way. The state of the parser changes as characters are read, so we can say there is a "context" that designates ...
SuperJMN's user avatar
  • 13.2k
1 vote
2 answers
1k views

Change current implementation of basic MVVM to adhere to SOLID pattern

I have been writing all my MVVM application with basic design pattern generally mentioned in MVVM examples available online. The pattern that I am following is described below: Model This section ...
Balraj Singh's user avatar
  • 3,391
8 votes
2 answers
2k views

Command Query Separation: commands must return void?

If CQS prevents commands from returning status variables, how does one code for commands that may not succeed? Let's say you can't rely on exceptions. It seems like anything that is request/response ...
MKaras's user avatar
  • 2,063
0 votes
0 answers
528 views

C# Query Object Pattern: Have query return IEnumerable or single result on generic interface

I have an interface which runs a query based on the query parameter and the query result public interface IQueryParam {} public interface IQueryResult {} public interface IQuery<in TQueryParam, ...
jmzagorski's user avatar
  • 1,135
3 votes
2 answers
616 views

Why does the CQS principle require a Command not to return any value?

The CQS principle says every method should either be a command that performs an action, or a query that returns data to the caller, but not both. It makes sense for a Query not to do anything else, ...
Daniel B's user avatar
  • 4,175
1 vote
0 answers
839 views

Understanding event-driven in a Spring MVC application

I've read the code from this Spring MVC application: https://github.com/spring-guides/tut-rest/tree/master/6/complete/src/main/java/com/yummynoodlebar/core/events I don't understand the role of ...
Sorin Vladu's user avatar
  • 1,768
0 votes
1 answer
172 views

Spring - passing a custom instance to a constructor

I'm trying to implement a command-query design pattern into a MVC spring based application. I have, for example, some decorated commands using decorator pattern like bellow: ICommandHandler handler =...
Sorin Vladu's user avatar
  • 1,768
4 votes
2 answers
2k views

Should the rule "one transaction per aggregate" be taken into consideration when modeling the domain?

Taking into consideration the domain events pattern and this post , why do people recomend keeping one aggregate per transaction model ? There are good cases when one aggregate could change the state ...
Tudor's user avatar
  • 1,143
1 vote
2 answers
980 views

CQS and CRUD operation

I working on high-scalability web site for learning purpose. I decided to use CQS pattern and some ideas of CQRS. I have separate write and read layers used by command handlers and event handlers ...
geek's user avatar
  • 596
3 votes
3 answers
460 views

Violation of Command-Query Separation while creating new database entry

I have a method that creates some entry in database and returnes it's Id. I would like to somehow separate these two because it violates Command-Query Separation. e.g. method (simplified): int ...
Miro's user avatar
  • 1,778
2 votes
1 answer
1k views

How to Read and Write using CQS

I'm going to start off a new project with CQS (as one aspect of its design), but NO CQRS + Event Sourcing, or Event Streaming, or Historical Modeling. When I come across a situation in which I will ...
Aaron's user avatar
  • 3,068
0 votes
1 answer
447 views

CQS queries - Auto generate ADO Mapping to View models?

I am currently working on an MVC 4 application. I am planning to implement a command query seperation pattern to enhance performance and the structure of the application. I am happy with my commands ...
jonho's user avatar
  • 1,690
3 votes
1 answer
657 views

Exceptions to the "Command-Query Separation" Rule?

Command-Query Separation "states that every method should either be a command that performs an action, or a query that returns data to the caller, but not both. In other words, asking a question ...
RyanScottLewis's user avatar
2 votes
3 answers
973 views

Command/Query separation when using an ORM

Within my various projects I implement the command/query separation pattern and use NHibernate as my ORM. In general I keep my commands and queries in separate projects relevant to the particular set ...
Jamie Dixon's user avatar
  • 53.1k
4 votes
2 answers
751 views

WPF Client - Should I make calls to WCF service in background thread?

I have a WPF client that makes calls to 2 WCF services. One service is for querying only and one service is for commands (CQS pattern). How should I make the calls to the commands service ? I read ...
John Miner's user avatar
6 votes
3 answers
2k views

Using the Command-Query Separation principle in MVC Controllers

I like the idea of Command Query Separation but can't see how to use it within an MVC Controller action which is adding an entity, and needs the new entity's ID after adding it. For example, in the ...
Appetere's user avatar
  • 6,003
7 votes
5 answers
907 views

Are fluent interfaces a violation of the Command Query Separation Principle?

I started writing a fluent interface and took a look at an older piece Martin Fowler wrote on fluent interfaces (which I didn't realize he and Eric Evans coined the term). In the piece, Martin ...
David Hoerster's user avatar
0 votes
1 answer
231 views

Can I break CQS to ensure less chatty web service interfaces?

I have a .NET WPF smart client calling a .NET WCF web service. The web service does most of the work and returns a small amount of information to the client. As such it's not entirely unlike a browser....
Neil Barnwell's user avatar
6 votes
4 answers
2k views

Python naming conventions for functions that do modify the object or return a modified copy

What would be the naming conventions in Python for functions that can return a modified object or that just modifies the instance. Let's assume you want to implement both, how you should name the ...
sorin's user avatar
  • 162k
1 vote
4 answers
697 views

Command Query Separation violation

What do you think about if(!DoSomething()) return; In Clean Code this is viewed as violation of Command Query Separation. But how can we understand if something in command DoSomething() went wrong?...
Vladimir Nani's user avatar
8 votes
3 answers
410 views

Abuse of Closures? Violations of various principles? Or ok?

Edit: fixed several syntax and consistency issues to make the code a little more apparent and close to what I actually am doing. I've got some code that looks like this: SomeClass someClass; var ...
Derick Bailey's user avatar
69 votes
9 answers
21k views

How would one apply command query separation (CQS), when result data is needed from a command?

In wikipedia's definition of command query separation, it is stated that More formally, methods should return a value only if they are referentially transparent and hence possess no side ...
Mark Rogers's user avatar
  • 96.6k
1 vote
4 answers
1k views

CQS and ASP.NET MVC Actions

Those who have read about CQS principle know that: CQS states that every method should either be a command that performs an action, or a query that returns data to the caller, but not both. ...
Mosh's user avatar
  • 5,944