Cqrs architecture model practice case: Tiny Library: System Architecture

Source: Internet
Author: User

Preface

Maybe I have read the previous articleArticleAfter I listed that part of the information, I still have many friends who do not know about the domain-driven design. As some netizens mentioned in the above comments, the Spanish Microsoft team also made a case of a domain-Oriented Distributed Application System architecture. The address is http://microsoftnlayerapp.codeplex.com /. On the homepage of this site, I have explained the domain-driven design. I think it is a good summary. I specially translated it into Chinese and wrote it here for your reference:

Ddd is much more than this!

We're re talking about complex apps ..., All their business rules (domain logic) are points that, in most of the cases, need to be changed quite a lot during the app's life. so it is critical to be able to change the app and test it in an easy way and independently from infrastructure areas (technology, data stores, data access using lgies, orms, etc .). because of that, it is important to have the domain/business layer (domain logic, entities, etc .) decoupled from the other layers.
Having said so, in our opinion, the best actual neural tural style that fits with those requirements isDomain oriented N-layered architecture Which Is Part Of DDD (Domain Driven Design) . And This sample-app is showing a way to implement a domain oriented N-layered architecture .
But, and this is extremely important, DDD is on the other hand, much more than just a proposed architecture and patterns. ddd is a way to build apps, a way for the team, to work in projects. According to DDD, the project's team shocould work in a specific way, shocould have direct communication with the domain experts (the customer, in our cases). The team shocould use 'Ubiquitous language' Which has to be the same language/terms used by the domain experts, etc.But, all those ways to work are not part of this sample-app , Because it is process, kind of Alm, so, If you want to really "Do DDD" , You'll need to read Eric-Evans 'book or any other DDD book where they talk about the DDD process, about the project and the team, not just the architecture and patterns. architecture and patterns are just a small part of DDD, but, in this case those are the points we are showing here (DDD architecture and patterns ). But we want to highlight that DDD is much more than architecture and design patterns .

 

Ddd-not just these

We are discussing complex application systems ......, With the business rules (domain logic) of these application systems, we can understand that in most cases, the business rules are a variable part of the entire lifecycle of the application system. Therefore, it is easy to change and test application systems and make them independent from infrastructure (such as technology, data storage, data access technology, Orm, etc ), it is very important. Because of this, it is necessary for us to decouple the domain/business layer (domain logic, entity, etc.) from other layers.

Even so, according to our suggestions, the architecture style that can meet the above requirements is a domain-Oriented Multi-layer architecture, but it is only a part of the domain-driven design (DDD. This case shows how to implement a domain-Oriented Multi-layer architecture. However, it is important to note that DDD is not only an architecture + mode. Ddd is used to develop applications.ProgramIs a way for a team to work in a project. According to DDD, the project team needs to cooperate in a special way and should be able to communicate directly with field experts (usually customers. The entire team needs to use the "general language", a language that everyone can accept, and so on. However, this case does not contain this content because it is a "process" or an ALM. Therefore, if you really want to practice DDD in 100%, you need to read the book "Domain-driven design-how to deal with core software complexity" written by Eric Evans, or other books that discuss the DDD process will give a detailed introduction to the DDD process, project, and team, not just about the architecture and model. Architecture and pattern are only a small part of DDD, and what we show here is exactly this part. In short, we must emphasize that DDD is not just an architecture + model.

Many netizens have a lot of controversy over what DDD is. I think the question should be roughly clear after reading the above text. I also borrowed this text to illustrate my intention to study and learn the practice of DDD. This article will give a brief introduction to the solution structure and system architecture of tiny library cqrs (tlibcqrs for short, the same below.

 

Tiny library cqrs Solution Structure

From the Solution Explorer, we can see that tlibcqrs contains nine projects, which are:

    • Tinylibrary. commandhandlers: The command processor responsible for processing command requests from the client.
    • Tinylibrary. commands: Command set, which contains the commands used by tlibcqrs. client requests are converted to commands and processed and executed by the command processor.
    • Tinylibrary. Domain: domain model. The business logic is the same as tiny library in the previous series. However, you will find that the tlibcqrs domain model differs from the domain model of the typical tiny library in terms of implementation.
    • Tinylibrary. eventhandlers: domain event processor, responsible for processing domain events forwarded by domain warehousing
    • Tinylibrary. Events: domain event set, which contains all domain events in tlibcqrs. These domain events have resulted in State updates for the entity in the domain model.
    • Tinylibrary. querobjects: queries an object set and is responsible for data query and transmission. It is a data ing on the user interface and is a DTO
    • Tinylibrary. Services:. Net WCF services, which contains two endpoints: commandservice and queryservice, provide services for the user interface layer.
    • Tinylibrary. tests: single test project
    • Tinylibrary. webapp: user interface implemented based on ASP. NET MVC

I still want to explain that this case has not added too many cross-cutting infrastructure. Therefore, log, cache, and exception handling are weak or even absent. Do not be curious, this is just a demonstration. To save time, I ignored this part. I will add it in the future.

 

System Architecture

The system architecture of tlibcqrs is the classic cqrs architecture. In my previous article titled entityframework-driven design practices [extended Reading]: cqrs architecture model, I have provided a brief diagram of the structure of the entire system, and I will post it again to represent the system architecture of tlibcqrs.

 

To let everyone see tlibcqrsSource codeConvenience. Here we will take "creating readers" as an example to describe sequence.

    • the client sends a createreader request to the system through tinylibrary. Services. commandservice
    • commandservice obtains the request, creates a registerreadercommand object, and pushes it to the command bus.
    • when the command bus is submitted, it will call registerreadercommandhandler to process registerreadercommand
    • In registerreadercommandhandler, create a new reader entity and send the readercreatedevent event to it.
    • after a reader object captures readercreatedevent, it sets its own state attribute based on the data in the event and records the event.
    • registerreadercommandhandler calls domain repository to save the new reader entity
    • domain repository reads the list of unsubmitted events from the reader entity and saves the events to the external persistence mechanism (tinylibraryeventdb in tlibcqrs).
    • after the event is saved, domain repository pushes the event to the event bus and returns
    • after the event is received by the event bus, use the message dispatcher to send the event to the corresponding event processor for processing.
    • after receiving the readercreatedevent event, readercreatedeventhandler saves the event data to the query storage mechanism (tinylibraryquerydb in tlibcqrs) and returns the data
    • in the next round, when you need to obtain reader information, you can directly read the query and storage mechanism through tinylibrary. Services. queryservice to obtain data.

The following UML sequence digoal can be used to describe this process 【Click here to download the XPS file to view the large image]:

 

In the next lecture, I will introduce some new ideas in tlibcqrs. As for the design of the cqrs framework, I will detail it in another series of articles.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.