当前位置:网站首页>How to use cqrs to effectively cut the code base according to business functions?
How to use cqrs to effectively cut the code base according to business functions?
2021-09-15 04:33:40 【Jiedao jdon】
The structure of items and discussion spaces are as sensitive as tab or indent size . When we enter someone's apartment , Even if it is decorated according to IKEA's default settings , It always looks a little different . It's absolutely reasonable . Different apartment sizes and room layouts will vary .
It's similar to our software project . Each has slightly different assumptions and characteristics , But some common features can be distinguished , Am I right? ?
Like everyone else , I started with a strict technical split , There I have one for service 、 contract 、 mapper 、 Folder of data model, etc . at that time , I think I had everything original and appropriate at that time . However , This assumption has changed .
Some time ago , I am here .NET In the example, I changed my event source . Now? , They are completely divided according to business functions , Not technical features . Why did I do this ?
My path to making this decision is gradual . When I create a repository , I'm at the stage of dividing the system into modules . Each module is a separate project . The first Department of the project is aggregation , So it's a business sub module . However , In the folder , The division is still technical . command 、 event 、 Value objects are distributed in different subfolders .
This is an acceptable solution , But I still feel uneasy . The breakthrough took place in ……
... I am here Angular Work longer on . stay “ new Angular” in , Decomposing the code base into components is essential . In the same folder , We kept HTML Views and components TypeScript Code . what's more , We also put unit tests together ! At first , I think it's strange , But then I realized that it helped to improve efficiency .
Usually , When we deal with a given business function , We use the same template :
- API Endpoint ,
- Request type ,
- Some classes to handle it ,
- Data model .
Traditionally , We spread it to different places . We have to be in multiple folders 、 Jump between files, etc . Of course ,IDE Shortcuts can help us do this , But we have to constantly jump from one place to another, and that hasn't changed . We always switch contexts . When we are interrupted by phone calls or social media announcements , I don't need to tell you , You'll know for yourself how inefficient it is to work in this situation .
The jump between files can be compared with this : When we put everything nearby , Preferably in a file , We can be more efficient . We may not even need three monitors or a monitor as wide as a football player's shoulder .
Keep this split right CQRS Very effective . It isolates our operations and splits the application code vertically rather than horizontally . Event traceability introduces more important improvements , Because we don't need a unified data model ( for example EntityFramework Medium DBContext). Each operation is based on events that we can save in the command folder .
It looks something like this :
stay Carts The business function file has the following subdirectories :
- Files with commands and handlers , for example Carts/AddingProduct/AddProduct.cs
- File with event command is being created , for example Carts/AddingProduct/ProductAdded.cs
- Use the handler to query , for example Carts/GettingCartById/GetCartById.cs
- Use projection to read the model , for example Carts/GettingCartById/CartDetails.cs
Of course , No, CQRS or Event Sourcing Projects can also benefit . Rule of thumb : Put things that change together . In addition to reducing context switching , This splitting can also improve the understanding of what is happening in the business , Manage dependencies and even eventually extend . It is easier to extract features into special objects Microservices in .
版权声明
本文为[Jiedao jdon]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/09/20210909112805266H.html
边栏推荐
- L'offre d'une grande usine est douce.
- 大廠Offer拿到手軟啊,程序員中年危機
- Stockage de produits Cloud packages, illimité et gratuit
- Opencv4 machine learning (VI): principle and implementation of k-means
- [yolop interpretation] you only look once for panoramic driving perception
- Tencent Cloud et d'autres systèmes de protection préférentiels
- Nombre maximum de points en ligne droite
- [interpretation of pointpillars] fast encoder for point cloud target detection
- [rangenet + + interpretation] fast and accurate lidar semantic segmentation
- [yolof interpretation] you only look one level feature (CVPR 2021)
猜你喜欢
-
[SNE roadseg interpretation] pavement segmentation network combined with surface normal vector (eccv2020)
-
[yolox interpretation] anchor free target detector comparable to yolov5!
-
Opencv4 machine learning (4): geometric transformation and affine transformation of images
-
Detailed explanation of fast SCNN semantic segmentation network
-
萬字長文,面試官老愛問適配器模式與外觀模式,
-
大牛耗时一年最佳总结,让你的app体验更丝滑,BAT大厂面试总结
-
不敢跟面试官对线,通过五轮面试斩获offer阿里实习生亲述,
-
Comparison of location loss functions in target detection network: IOU, giou, ciou, Diou, L1, L2, smooth L1
-
Blue Bridge Cup software provincial competition in April 2021: title + analysis (full version)
-
[C + + cultivation plan] don't talk about learning, just talk about dry goods (Day1)
随机推荐
- Tf2.0 deep learning practice (1): handwritten numeral recognition for classification problem
- 大廠程序員35歲後的職業出路在哪,京東最新Android面試真題解析
- Invitation | réunion Apache Pulsar 2021 - Shenzhen ce samedi
- The Dot Net Application Domain Study
- Trigger study
- Universal code, achieving with action -- Safety code scanning Professional Committee
- N'osez pas vous opposer à l'intervieweur et obtenir des commentaires personnels des stagiaires d'offer Ali après cinq rondes d'entrevue.
- Daniel prend le meilleur résumé de l'année pour rendre votre expérience d'application plus soyeuse.
- Easy to use and convenient development team management tool -- apipost
- 如何试出一个Android开发者真正的水平,【面试总结】
- 如何才能通过一线互联网公司面试,Android经典入门教程
- Comment passer une entrevue avec une entreprise Internet de première ligne, Android Classic Getting started tutoriel
- Comment essayer un développeur Android vraiment niveau, 【 résumé de l'entrevue 】
- Ad redefines PCB size
- [wonderful learning journey of cloud computing] phase I: getting to know cloud computing for the first time
- Sf58-asemi high voltage fast recovery diode in-line package
- Asp.net quick build application page main framework
- Soul painter: cartoon illustration SSH
- Special live broadcast of the first anniversary celebration of Hongmeng community · invitation letter
- Mathematics Interview Questions (X)
- 如何才能通過一線互聯網公司面試,Android經典入門教程
- 3分钟带你了解,软件测试工程师的一天!
- 程序人生 | 95年男,做了3年销售,能转行IT是我的幸运!
- 35岁软件测试工程师,都在慌什么?
- How does atomicstampedreference solve the ABA problem of CAS
- A buffer queue with extreme performance
- How difficult is it to implement a counter with higher performance than longadder
- What do we talk about when we talk about the registry
- Skywalking memory leak troubleshooting
- Getting started with openresty
- 35歲軟件測試工程師,都在慌什麼?
- 程序人生 | 95年男,做了3年銷售,能轉行IT是我的幸運!
- Ingénieur de Test logiciel de 35 ans, pourquoi paniquer?
- La vie du programme | 95 ans homme, a fait 3 ans de vente, peut être transféré en it est ma chance!
- 3 minutes pour vous faire comprendre la journée de l'Ingénieur de Test logiciel!
- Venez vous entraîner, un projet d'évaluation en ligne similaire à la boucle de force
- Créer des applications distribuées d'une manière simple
- Inventory development artifact in golang
- Async profiler, a sharp tool for CPU analysis
- Ast, it smells good