How To Use Domain-Driven Design In Clean Architecture

preview_player
Показать описание

Clean architecture is a good choice when you want to design a robust and flexible application. The core of the Clean Architecture is the Domain layer. This is where you should define your important domain (or business) rules. In this video, I will show you how to go from an Anemic Domain model to a Rich Domain model by moving the application logic into the Domain layer. We will apply some of the concepts from Domain-Driven Design.

Join my weekly .NET newsletter:

Subscribe for more:

Chapters
0:00 What we are going to build
1:23 Anemic domain model
2:54 Refactoring to a rich domain model - Part 1
4:33 Static factory pattern
8:16 Refactoring to a rich domain model - Part 2
11:21 How to encapsulate collections
16:35 Refactoring to a rich domain model - Part 3
18:32 Moving logic to the domain layer
21:49 How to encapsulate collections (again)
24:15 How to deal with external dependencies
28:12 Questions left unanswered
29:58 How to get the source code
Рекомендации по теме
Комментарии
Автор

Honestly. After few weeks of learning fundamentals of DDD, watching conferences, tutorials, reading blogs and articles about how and what to refactor, why this or that way, when and what set to private/internal or leave public I can say with 100% sure - this is the best explained video concerning this topic. Now its going to be easier for me to refactor my learning projects from anemic to rich model and be motivated to write code again :)

newraze
Автор

Good! wasn't it better to call AsReadOnly method to return IReadOnlyCollection. This way (not using this method) clients may simply cast the collection as List<> and modify it

hosseinnarimanirad
Автор

Which program are you using for drawing class diagram? 1:10

mgame
Автор

Hi great video ! I have two noobie question :
1) at 9:32, in the SendInvitationCommandHandler, you create an invitation then you add it to the gathering.Invitations list (line 63) then add the invitation in its repo then SaveChanges(). What is the purpose of doing both? Cant we just add the invitation to the repository and SaveChanges OR add the invitation to the gathering.Invitations list and just SaveChanges since EF is tracking?

2) at 24:00 cant we just keep List<Attende> Attendees but give it a private set? Instead of making it a ReadOnlyCollection and create whole new field private?

Ty so much in advance!

UberEverywhereSKRT
Автор

You have a gift for comprehensive and precise communication without unnecessary filler material.

EmptyGlass
Автор

Hi, Milan
I'm not sure, that changing the Invitation's properties inside of the gathering is a good way because it looks like a side-effect. I think, that the Gathering class should only have the possibility to check the expiration and AddAttendee(attendee) method

Eless
Автор

I see return Unit.value where is that. Can't see it in the class anywhere

ravindranathwi
Автор

How would you go about translation to different languages? I mean mostly static error messages etc.

haruundk
Автор

When you are doing data validation video, could you take an example of the nature of "there should be no 2 members with the same name\email"? I'm interested in how you are going to avoid the data racing condition, when there are 2 simultaneous requests to create a user with the same name. I understand how the optimistic concurrency works on the level of an entity, but what are you going to do when it is not practical to aggregate all the data necessary for the validation in one entity?

marhoily
Автор

Great video, thanks, the short question, why do we use method name Gathering.SendInventation considering the fact that method does not perform any 'sending' logic and just add a newly created Inventation instance to the Gathering?

ПётрЗахаревич-эи
Автор

I would recommend reading about DDD starting from Von Vernon's "red" book and then reading Eric Evans's book.

hlazunov
Автор

Milan, needless to say that this was once again a great and awesome video :)

Great work picking a somehow complex topic and make it look like a simple action without being lost at the definition hell of DDD :)

tiagocandeias
Автор

I couldn't understand why did you something like that with Lists (in 15:18)
I think that EF core can handle all of them...
or may be you did this because you wanted to use other ORMs like dapper?
also i dindn't like adding SendInvitation into Entity... i think it's a buisness rule, and I have to implement that on application layer.

note that: i'm not a native guy so some times i can't translate my right meaning i'm Sorry if I was disrespectful, I like your videos very much

SoheilKhosroshahi
Автор

I really like how you explain complex concepts and designs in a such simple way. Extra butter to your videos is that examples are not "dead" - you try showing things on cases that are close to real domains. No "Foo" and "Bar" involved, which is really great!

timurrozhok
Автор

Great content, keep it up. I would like to see a video on separating your domain via bounded contexts and how that would work with EF.

paulbarton
Автор

Thanks Milan.

Shouldn't the commands and queries live in Domain and theirs handlers live in Application? Is there any wrong with this approach?

ghaiathaltrabulsi
Автор

An excellent video. What do you think about the opinion that domain driven design works well only if we know all of the project's business logic from the beginning and that this rarely happens in the real world?

And some folks claim in such situation it is better to use the more old school multi layer architecture with presentation, business and database layers and annemic models.

It would be great if you can shoot a video about comparing the pros and cons of both.

Pest
Автор

Insted of returning null, you can use the keyword "default". And thank you for your work Milan :-) you are doing good !

Mafyou
Автор

Great tutorial and awesome channel !
@11:09 why do you leave the guid as a constructor parameter ? Is that a bad practise to generate the guid directly in the constructor itself?

MickaelLY
Автор

Great video thanks! Can't wait for the next one to see how you gonna handle unanswered question with sending the email. As you told me on previous video probably it's going to be with mediatr publish notification. Keep up the great work!

newguycho