Simple command handler in .net

I want to introduce a simple command handler pattern in order to separate commands and queries of your applications, if it’s needed. Sometimes specially in large scale applications you need to have two layers for read and write separated and assign two teams to work on them.

You can use the pattern in this post based on complexity and needs of your application. I recommend that don’t call this CQRS pattern as it’s something completely different and more complex.


Get started and Create an interface with no any member:... Continue

Difference between layer super type and template method patterns

About two days ago I asked a question about the differences of these two patterns. after reading about the template method patterns in detail I found that although there are lots of similarities between them but layer super type is not the same as method template and vice versa. I've blogged about Layer Super type before in here, now I want to talk about method template pattern. Basical... Continue

Implementing thread safe Singleton pattern in C#

A singleton is a class which allows one instance of itself to be created and allow you to easy access to that instance. A singleton just gives you a single instance of a class. When you need a class that has only one instance. Singleton ensures you that a class has only one instance and also you have a global point to access that instance. This a simple example of singleton pattern.


  1.     public class ThreadSafeSingleton
  2.     {
  3.         private static volatile ThreadSafeSi... Continue

Dependency Inversion of SOLID principle

As you know, Dependency Inversion Principle is the last principle of SOLID. I talked about SOLID principle and fundamental in my previous post that was about SRP. Now I'm gonna to consider the dependency inversion of SOLID. Based on definition "High level modules should not depend upon low level module, both should be depend upon abstraction". Or in other definition "abstraction should not depend upon details, details should depend upon abstraction... Continue

Does it cause any kind of performance issue using a base class in Layer SuperType pattern?

I had a long discussion with one of my colleague about using a base class in Data access layer or repository instead of implementing all common scenario like CRUD operation for every aggregate. it's Layer SuperType pattern that I'm talking about. I've posted about Layer SuperType pattern before, but now I'm going to know that what will happen in an application with large amounts of requests and transactions to performance in the case of using base class for Common methods of DAL.

... Continue

Domain driven design VS model driven architecture

Domain Driven design(DDDesign) is not the same Model Driven Architecture(MDA). Although The root of both DDDesign and MDA is the same and it is Model Driven Engineering and also both of them aim to solve the problem of converting a 'pure' problem domain model into a full software system. But there are some differences.

Domain Driven Design concentrates on Modeling and solving the Domain problem by Capturing the model from Ubiquitous language. it is about m... Continue

Does CQRS innately need Domain Driven Design?

It's a hard question to answer, or Not? Maybe that's because of my lack of DDD and CQRS understanding. Anyway I'm not sure about what I'm writing in this post to be right and if there is any mistake, please let me know to correct that.

To the best of my knowledge Domain Driven Design is so useful for successfully delivering CQRS based applications but you don't need DDD whenever you want to apply CQRS pattern. CQRS is not intrinsically linked to DDD. CQRS is just a pattern and you use CQRS in a bounded context of a DDD app... Continue

Definition of Command Query Responsibility Segregation


What is CQRS ?

CQRS Is an alternative architecture and pattern for Domain Driven Design (But you don’t basically need DDD to apply CQRS). A method should either change state of an object, or return a result, but not both. In other word, asking the question should not change the answer. CQRS is a pattern that strictly segregates the responsibility of handling command input into an autonomous system from the responsibility of handling side-effect-free query (read) access o... Continue

Apply to request response pattern in your service layer

Messaging pattern is one of my favorite patterns to use in service layer! since I've read Pro Design pattern by ScottMillett I've been a big fan of patterns and how to apply them, in this article I'm going to talk about request response pattern.

"Design patterns that are associated in the realm of large-scale distributed applications like SOA systems are often referred to as Messaging patterns. Messaging patterns... Continue

Difference between Anemic Domain Model and Rich domain model

There are lots of differences between these to approach. Anemic model is an anti-pattern introduced by martin fowler to encourage developers to duplicate code!  Based on the main idea behind DDD, if you have ubiquitous language then you can have domain model Anemic domain model is the use of a software domain model where the domain objects contain little or no business logic. in a Rich Domain Model behavior is included in the domain object while in Anemic Domain Model behavior is implemented in separate classes.

At some point in the design of the... Continue