7

Should you use the Repository Pattern? With CQRS, Yes and No!

 2 years ago
source link: https://www.youtube.com/watch?v=01lygxvbao4
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
#softwarearchitecture #domaindrivendesign #cqrs

Should you use the Repository Pattern? With CQRS, Yes and No!

8,607 views
Premiered Oct 27, 2021

The repository pattern is polarizing. Some developers swear you should always use it to abstract data access logic while others think it's unnecessary if you're using an ORM. So should you use it? My answer is Yes and No! If you're applying CQRS and Vertical Slice Architecture you'll likely want a repository to build up Aggregates. However, for a Query, you may want to just get the data you need rather than an entire aggregate (or collection of aggregates) to build a view model.

🔗 EventStoreDB https://eventsto.re/codeopinion

🔔 Subscribe: https://www.youtube.com/channel/UC3RK...

💥 Join this channel to get access to source code & demos! https://www.youtube.com/channel/UC3RK...

🔥 Don't have the JOIN button? Support me on Patreon! https://www.patreon.com/codeopinion

📝 Blog: https://codeopinion.com 👋 Twitter: https://twitter.com/codeopinion ✨ LinkedIn: https://www.linkedin.com/in/dcomartin/

0:00 Intro 0:56 CQRS & Vertical Slices 4:23 Query 7:16 Command

#softwarearchitecture #domaindrivendesign #cqrs

Show lessShow more

Buy CodeOpinion merchandise

45 Comments

Sort by
default-user=s48-c-k-c0x00ffffff-no-rj
Add a public comment...

I wish .NET engineers thought more like this. Implementing things based on need instead of matching patterns and what not 😣.

Can you make a video on vertical slice architecture and how to handle cross cutting concerns between features for that architecture?

Read more 3 weeks ago

Great view on repository pattern. With event sourcing the write side is pretty simple for storage interface requirements. Therefore I don't use EF there at all and use a custom repository instead. For read side EF would work better, but I tend to avoid it in my projects due to high technology coupling. Opinions...

3 weeks ago

It always surprises me how you can put so much information and explain it so concisely. Keep up the good work! Regarding the topic: I’m usually afraid “somebody” might tamper with the DB (manually), and therefore am also inclined to use my aggregates validations before I pass them to the UI in some form or another. But it’s like you say, consistent state is important when you’re mutating this state, so that would be AFTER a user sent some instruction, based on just data that was sent to their screen.

Read more 3 weeks ago

Thank you, Derek, for your thoughts and examples, it was always helpful to me!) After watching this video I have a question of how to map an entity to an EF model in your repository? How to do this if most of entity fields may have a private accessibility level?

3 weeks ago (edited)

Interesting! Never thought of this. Repositories are actually needed in writes because of aggregates and state consistency but not in reads. Aggregates are useless in reads so using extension methods on the db context is a good idea for testability. Interesting!

2 weeks ago

Great stuff! Thank you for the time you put into these videos.

2 weeks ago

Spot on. 100% agree, my understanding is that repository is a patern from DDD and it should be used together with as small as possible (to protect the business rules) agregates loaded eagerly. Every other similar abstraction is just a data access. The problem is that everyone seems to call those data access objects a "Repository". Thanks for the great content.

3 weeks ago


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK