Thursday, May 17, 2012

CQRS : Command Query Responsibility Segregation (A Design by contract methodology)

CQRS design pattern is generally used in Business Layer or Data-Access Layer, its purpose is to keep data access methods simple, and should adhere to their purpose.

It mandates Each method to perform a single operation and purpose of method should be clearly indicated by method name. For example if method name is GetEmployees then that method should only be returning Employees collection not modifying any employee object.

Using CQRS patter, lets design a Data access component for Employee , we will have a IEmployeeRepository Interface as shown below




As we can see for each action related to Employee Repository we have a method, and that method will only perform that operation (either command or query not both).

No comments:

Post a Comment