Thank you dear Milan. question about Models: 1- In [CommandHandlers] & [QueryHandlers] we have [Request Class] which is inherited from [IRequest]. 2- [Commands & Queries] class play a role like DTO which are used by handler class as input parameter. 3- [Queries] return a model and generally shall be different from [Domain] classes. If it is identical to [Domain] class, we create similar class (DTO) but don't expose domain class to upper layer. 4- So far, we have classes (Like Model) for commands (input) & queries (input) & DTO (output). 5- Item 1~4 can be used in API project and API project can be execute in server. 6- But, Client is a different project (WebApplication/WindowsForm/Android/…) and for sending/receiving data to/from API we need to have [Input Model] for command & query and get data in DTO format. Question: As mentioned above, is it suggested to define new command/query/DTO classes in different project (Not in Application/Infrastructure layers) to reference them to [Client] project so, we do not have to create extra and identical classes? Is it accepted? To clarify my previous question: Is it possible to create [Model] class (input and output) in separate class library and reference them to all other projects? In this way, [Command] class can inherit from [DTO+IRequest] together.
Hi Milan, i watch your content from a long time and also like it. I have a request can you try to keep content as beginner friendly so that if we share videos to someone, even if he has no context he can learn it easily and quickly
Very nice, like always. I'd agree with (at least one) comment that I saw asking for a mini app that implements all of this, because theory is nice, but seeing it actually in practice is even better. It doesn't have to have cqrs with mediatr or use a real db nor be a web app. It can just be a simple console app that fetches some data from in memory database. For example a library where you can list all the books or all the authors, you can add or remove books and/or authors. You can have some business rules like a book can't have more than 2 authors... I think it'd benefit the community a lot :)
I have at least three (that I can think of) series of implementing a CA project from scratch 😅 I can't fit that into one video, so I break it down into many separate lessons.
@@MilanJovanovicTech Fair enough, my bad then. I watch a lot of your clips, but I don't keep tabs what I've seen on your channel, what on some others :)
Thanks Milan I have a question about file upload, Is it ok if used IFormFile in Application project as a parameter in the IRequest class/record public record CreateArticleRequest(string Title, string Content, IFormFile ThumbnailImage) : IRequest; or create a custom class and map IFormFile to it in the controller public record CreateArticleRequest(string Title, string Content, FileUploader ThumbnailImage) : IRequest; public async Task CreateArticle([FromForm]CreateArticleRequest command,[FromForm] IFormFile formFile) { command.FileUpoader = formFile.MapToFileUploader(); //... } or you have a better approach ?
I think just passing down the IFormFile is fine. But this means you'd only be able to send this request in an ASPNET request (I think?). Not sure how to construct an IFormFile manually, is what I'm saying. An alternative is mapping the contents of the file, before processing it: name, bytes, size, content type.
I have your free clean arch template. I noticed that Web.API (Presentation) layer can access to the dbcontext object directly, Wouldn't be a problem to access DbContext object directly?
@@MilanJovanovicTech In this case, would it be architecturally appropriate to move the minimal api definitions to a different layer? I want to restrict access from APIs directly to the dbcontext object.
Hi Milan! I have a question for you. Let's say I have clustered postgresql server (1 - write node, 3 - read only access nodes). What would be my best strategy to implement some sort of load balancing on my database? Well I can do some custom singleton service which can provide me always next connection string, but will it be ok? I believe there is a better solution somewhere. Btw, I am using EF core
@@MilanJovanovicTech With the help of your videos, I've definitely improved! However, I'm still a beginner, currently learning about ASP NET project types
Thank you for this video. I have bin trying to find out where the API should go in clean Architecture but no one was giving a straight forward answer has you did here. I just have one more thing for you to clear up. The UI(Angular,React,Blazor) should this also go in the Presentation layer?
as always.. you are awesome, I wrote the following message before seeing the end of your video, { Is there any chance that we can see you create a mini system of your choice to show for your follow how the systems build in real world, how we should implement design principles, design patterns in the real world, how we do that after analysing the idea, how we convert it to diagram maybe, or to tasks using agile.. scrum or kanban, how to manage git effectively, how to publish it to azure or aws.. I know it's alot, if you'd like to do that.. make it on a paid platform and I'm sure most of your followers will participate } I wrote that before seeing the end of your video 😂 I hope two things about your course, first it's starting from scratch or let us say for bignner not for the people how have master degree as you do here in UA-cam, second it's convert the subjects that I mentioned above. thanks alot
- Check out some of the playlists I have. It's hours of videos building a CA project from scratch (Gatherly, eShop, Runtrackr) - I have another video touching on Azure deployment also (ua-cam.com/video/QP0pi7xe24s/v-deo.html) - For the course, take a look at the full Curriculum and some preview chapters.
I might be even more opinionated around what is allowed in the application layer, since I mostly like the functional core imperative shell version of clean architecture. That means that no side effect/ I/O is allowed when invoking methods outside the outer layers. Since I/O means unpredictability in the business logic this must be done carefully, since business logic should not depend on side effects while the outer shell can do so 👍
@@MilanJovanovicTech The use case may have I/O but it can only do so at the edges of the system. This means that the orchestration of the domain is not allowed to do I/O even through an interface, since that only masks the I/O. I/O introduces indeterminism and should therefore be avoided when making returning a result, which is all that business logic should ideally be doing. Any action you take as a consequence of that result is not the concern of the business logic but at a higher level of a use-case if you will. In this way you separate results from actions, so that the same logic can be used to take different actions depending on the context of the use-case.
Could you make any quick step by step guide for mid level developer for better understand this idea without CQS or with repository unit of work and services DP..
Thank you for providing valuable information in the .NET environment, Milan. I've been following you for some time now, but I'm in need of a mentor in Java. Do you happen to know anyone who could help?
Seems like clean architecture isn't very popular outside the OOP languages like C# and Java. I've been transitioning to python the last few months and I can't seem to find a good clean architecture examples. Maybe because in python they don't really abstract much of the implementation details, unlike in C# dan Java?
Please no offense, The issue with all your CA videos (at least for me) is that in all of them you either don't show an actual project or even when you do, you never show the folders/files structures or hierarchies. I've watched many of your videos yet couldn't figure out how to setup even a basic CA project. Suggestion: 1- Create a new .NET project 2- Create the needed folders 3- Place each file to its relative folder. e.g. Controller, Repo, Entity/Model, Dto, Db, etc. 4- Explain how they are connected and related to each other. If I would rank C# UA-cam videos based on being practical and helpful: #1 kudvenkat (the best) #2 IAmTimCorey #2 You #3 Nick Chapsas (the worst) I hope it helps you improve your contents. To be honest some of your videos are just great I have to add that. Best regards.
Look at it from a creator's perspective. There are a few issues I'm faced with. Let's say I want my videos to be 15-20 minutes long. This is long enough to pack some helpful info inside but not so long that it becomes boring. And there lies the problem. So, I must sacrifice something to fit the format I want to produce. Most of the time, I end up assuming the viewer has some prior experience with a certain topic or is a more experienced developer. With that in mind, I assume the viewer should be able to follow most of the videos and take away the key points I want to convey. Sometimes, I succeed, and sometimes, I don't. I'm not perfect. My second point is about having time to produce good content. I sacrificed the quality in the past few weeks (and a few incoming weeks) to have time to work on my new Modular Monolith course. Which is almost ready for release. This means I'll have more time to focus on creating quality content, and I'm excited about it. :)
@@MilanJovanovicTech That's beautiful. I absolutely admire you for creating these contents along with your own crouse works at the same time. Your last paragraph is actually very motivating ❤️. I see you have many CA videos. Maybe if the first videos were a bit more fundamental then building up from there in the next short videos would help us a bit more. Most people like me who look for a tutorial on UA-cam usually don't know much about the particular subject, otherwise, we'd go for Stackoverflow, Gemini, ChatGPT etc. Every time you upload a CA video I open it hoping this one is gonna show me how to do it 😂 and I've been failing over and over so far. Thanks for sharing your viewpoint and situation. Good luck with your new courses. 🍻
I've followed all your videos about hexagonal, clean architecture, DDD, layered and adapters and ports. And at this point i have no idea what it supposed to be, same on linkedin. You are mixing and overconfusing tons of stuff or im not experienced enough which is which at this point.
I disagree. I think Milan has put together a very clear architecture. Every layer is focused only on one area of the system. E.g: Domain does only one thing and is loosely coupled from other layers. I've been in this for over 20 years, and I've seen many attempts to put together a good architecture. Milan's is one of the best, mixing structure with pragmatism and following all SOLID principles.
@@MilanJovanovicTech I prefer to keep database information out of the application. In this case, application layer knows db connection, type of db, db scheme. Pretty much everything.
You are not right with the point that presentation and infrastructure layers can reference each other. Just define an interface for what you need in application layer, then implementation in outer layers for that and it is solved. Why take shortcuts?
Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
Finally a video about this topic that actually makes sense and not a 20 minutes long time-waste.
Glad you enjoyed it 😁
Very good examples and great advice for good practices! You are a great teacher
Glad it was helpful!
Thank you dear Milan. question about Models:
1- In [CommandHandlers] & [QueryHandlers] we have [Request Class] which is inherited from [IRequest].
2- [Commands & Queries] class play a role like DTO which are used by handler class as input parameter.
3- [Queries] return a model and generally shall be different from [Domain] classes. If it is identical to [Domain] class, we create similar class (DTO) but don't expose domain class to upper layer.
4- So far, we have classes (Like Model) for commands (input) & queries (input) & DTO (output).
5- Item 1~4 can be used in API project and API project can be execute in server.
6- But, Client is a different project (WebApplication/WindowsForm/Android/…) and for sending/receiving data to/from API we need to have [Input Model] for command & query and get data in DTO format.
Question:
As mentioned above, is it suggested to define new command/query/DTO classes in different project (Not in Application/Infrastructure layers) to reference them to [Client] project so, we do not have to create extra and identical classes? Is it accepted?
To clarify my previous question:
Is it possible to create [Model] class (input and output) in separate class library and reference them to all other projects? In this way, [Command] class can inherit from [DTO+IRequest] together.
I end up just exposing a Request/Response object for the API layer. And then use Command/Query internally.
thanks, even for Senior devs, this is a great refresher
The fundamentals always apply
Looking forward to talking more about the modular monolithic architecture
More videos are already scheduled :)
@@MilanJovanovicTech 🤩😙
Hi Milan, i watch your content from a long time and also like it. I have a request can you try to keep content as beginner friendly so that if we share videos to someone, even if he has no context he can learn it easily and quickly
That depends on the video
Amazing content, thank you for this playlist about Clean Architecture, DDD and related topic
Glad you liked it!
Thanks for this, Milan. Your content is always top-notch.
Most welcome!
simply the best! simple and to the point. Thank you
You're welcome!
Very nice, like always. I'd agree with (at least one) comment that I saw asking for a mini app that implements all of this, because theory is nice, but seeing it actually in practice is even better. It doesn't have to have cqrs with mediatr or use a real db nor be a web app. It can just be a simple console app that fetches some data from in memory database. For example a library where you can list all the books or all the authors, you can add or remove books and/or authors. You can have some business rules like a book can't have more than 2 authors... I think it'd benefit the community a lot :)
I have at least three (that I can think of) series of implementing a CA project from scratch 😅 I can't fit that into one video, so I break it down into many separate lessons.
I build a real SaaS platform using these patterns: ua-cam.com/video/zuOwzVWpo8I/v-deo.html Feel free to question everything is happening there
@@MilanJovanovicTech Fair enough, my bad then. I watch a lot of your clips, but I don't keep tabs what I've seen on your channel, what on some others :)
Thanks Milan
I have a question about file upload, Is it ok if used IFormFile in Application project as a parameter in the IRequest class/record
public record CreateArticleRequest(string Title, string Content, IFormFile ThumbnailImage) : IRequest;
or create a custom class and map IFormFile to it in the controller
public record CreateArticleRequest(string Title, string Content, FileUploader ThumbnailImage) : IRequest;
public async Task CreateArticle([FromForm]CreateArticleRequest command,[FromForm] IFormFile formFile)
{
command.FileUpoader = formFile.MapToFileUploader();
//...
}
or you have a better approach ?
I think just passing down the IFormFile is fine. But this means you'd only be able to send this request in an ASPNET request (I think?). Not sure how to construct an IFormFile manually, is what I'm saying.
An alternative is mapping the contents of the file, before processing it: name, bytes, size, content type.
An excellent explanation about clean architecture. 🙂
Glad you liked it!
I have your free clean arch template. I noticed that Web.API (Presentation) layer can access to the dbcontext object directly, Wouldn't be a problem to access DbContext object directly?
They're on the same level, so it's fine. Plus, you need to wire up DI somehow.
@@MilanJovanovicTech In this case, would it be architecturally appropriate to move the minimal api definitions to a different layer? I want to restrict access from APIs directly to the dbcontext object.
@@omerabay Do it with architecture tests. Adding another project works, but you end up spreading yourself thin
@@MilanJovanovicTech I understand now thank you very much :)
Hi Milan! I have a question for you. Let's say I have clustered postgresql server (1 - write node, 3 - read only access nodes). What would be my best strategy to implement some sort of load balancing on my database? Well I can do some custom singleton service which can provide me always next connection string, but will it be ok? I believe there is a better solution somewhere.
Btw, I am using EF core
Isn't there a Postgres client library that can take care of that? 🤔
I'm truly fascinated by this topic, thanks to your excellent explanation. I aspire to reach your level of knowledge in the future.
Wow, thank you! Are you using Clean Architecture in your projects?
@@MilanJovanovicTech With the help of your videos, I've definitely improved! However, I'm still a beginner, currently learning about ASP NET project types
Thank you for this video. I have bin trying to find out where the API should go in clean Architecture but no one was giving a straight forward answer has you did here. I just have one more thing for you to clear up. The UI(Angular,React,Blazor) should this also go in the Presentation layer?
The client (UI) is usually a separate application - but in general, yes
@@MilanJovanovicTech thanks for clearing this up for me.
as always.. you are awesome,
I wrote the following message before seeing the end of your video,
{
Is there any chance that we can see you create a mini system of your choice to show for your follow how the systems build in real world, how we should implement design principles, design patterns in the real world, how we do that after analysing the idea, how we convert it to diagram maybe, or to tasks using agile.. scrum or kanban, how to manage git effectively, how to publish it to azure or aws.. I know it's alot, if you'd like to do that.. make it on a paid platform and I'm sure most of your followers will participate
}
I wrote that before seeing the end of your video 😂
I hope two things about your course,
first it's starting from scratch or let us say for bignner not for the people how have master degree as you do here in UA-cam,
second it's convert the subjects that I mentioned above.
thanks alot
- Check out some of the playlists I have. It's hours of videos building a CA project from scratch (Gatherly, eShop, Runtrackr)
- I have another video touching on Azure deployment also (ua-cam.com/video/QP0pi7xe24s/v-deo.html)
- For the course, take a look at the full Curriculum and some preview chapters.
I build a real SaaS platform using these patterns: ua-cam.com/video/zuOwzVWpo8I/v-deo.html Feel free to question everything is happening there
Hi Milan, I'm learning about EF core. But I don't know what is default loading in EF core, can you explain me about this?
I'd always refer to the docs if you have a basic EF question
I might be even more opinionated around what is allowed in the application layer, since I mostly like the functional core imperative shell version of clean architecture. That means that no side effect/ I/O is allowed when invoking methods outside the outer layers. Since I/O means unpredictability in the business logic this must be done carefully, since business logic should not depend on side effects while the outer shell can do so 👍
So your use case can't have any I/O?
@@MilanJovanovicTech
The use case may have I/O but it can only do so at the edges of the system. This means that the orchestration of the domain is not allowed to do I/O even through an interface, since that only masks the I/O. I/O introduces indeterminism and should therefore be avoided when making returning a result, which is all that business logic should ideally be doing. Any action you take as a consequence of that result is not the concern of the business logic but at a higher level of a use-case if you will. In this way you separate results from actions, so that the same logic can be used to take different actions depending on the context of the use-case.
Could you make any quick step by step guide for mid level developer for better understand this idea without CQS or with repository unit of work and services DP..
Probably
Very good explanation
Thanks a lot!
Thank you for providing valuable information in the .NET environment, Milan. I've been following you for some time now, but I'm in need of a mentor in Java. Do you happen to know anyone who could help?
No, sadly I don't follow any Java devs (they can't C#)
what is Orchestrates the Domain
= Tell it what to do
What is the "pragmatic approach" you prefere instead of "Clean Architecture"? is DDD ?
It's basically CA + a more "loose" way to think about that's less strict. Fewer abstractions, same direction of dependencies.
Thanks! Repository abstraction, in my opinion, should be at the application layer. It has nothing to do with the core business logic
Your opinion vs mine 😁 At the end of the day, it's just an opinion. What matters is working software.
@@MilanJovanovicTech Hi, just curios why did you put the repository abstraction in the domain layer?
Seems like clean architecture isn't very popular outside the OOP languages like C# and Java. I've been transitioning to python the last few months and I can't seem to find a good clean architecture examples. Maybe because in python they don't really abstract much of the implementation details, unlike in C# dan Java?
That could be the reason, yeah 🤔
Please no offense,
The issue with all your CA videos (at least for me) is that in all of them you either don't show an actual project or even when you do, you never show the folders/files structures or hierarchies. I've watched many of your videos yet couldn't figure out how to setup even a basic CA project.
Suggestion:
1- Create a new .NET project
2- Create the needed folders
3- Place each file to its relative folder. e.g. Controller, Repo, Entity/Model, Dto, Db, etc.
4- Explain how they are connected and related to each other.
If I would rank C# UA-cam videos based on being practical and helpful:
#1 kudvenkat (the best)
#2 IAmTimCorey
#2 You
#3 Nick Chapsas (the worst)
I hope it helps you improve your contents. To be honest some of your videos are just great I have to add that.
Best regards.
Look at it from a creator's perspective. There are a few issues I'm faced with.
Let's say I want my videos to be 15-20 minutes long. This is long enough to pack some helpful info inside but not so long that it becomes boring. And there lies the problem.
So, I must sacrifice something to fit the format I want to produce. Most of the time, I end up assuming the viewer has some prior experience with a certain topic or is a more experienced developer. With that in mind, I assume the viewer should be able to follow most of the videos and take away the key points I want to convey. Sometimes, I succeed, and sometimes, I don't. I'm not perfect.
My second point is about having time to produce good content. I sacrificed the quality in the past few weeks (and a few incoming weeks) to have time to work on my new Modular Monolith course. Which is almost ready for release. This means I'll have more time to focus on creating quality content, and I'm excited about it. :)
@@MilanJovanovicTech That's beautiful. I absolutely admire you for creating these contents along with your own crouse works at the same time. Your last paragraph is actually very motivating ❤️.
I see you have many CA videos. Maybe if the first videos were a bit more fundamental then building up from there in the next short videos would help us a bit more. Most people like me who look for a tutorial on UA-cam usually don't know much about the particular subject, otherwise, we'd go for Stackoverflow, Gemini, ChatGPT etc. Every time you upload a CA video I open it hoping this one is gonna show me how to do it 😂 and I've been failing over and over so far. Thanks for sharing your viewpoint and situation. Good luck with your new courses. 🍻
love you 😙
Thank you! :)
Very good
Thanks
I've followed all your videos about hexagonal, clean architecture, DDD, layered and adapters and ports. And at this point i have no idea what it supposed to be, same on linkedin. You are mixing and overconfusing tons of stuff or im not experienced enough which is which at this point.
I never talked about hexagonal, though. Can you explain which part is causing you confusion?
I disagree. I think Milan has put together a very clear architecture. Every layer is focused only on one area of the system. E.g: Domain does only one thing and is loosely coupled from other layers.
I've been in this for over 20 years, and I've seen many attempts to put together a good architecture. Milan's is one of the best, mixing structure with pragmatism and following all SOLID principles.
@@ronnythedev The issue seems to be "You're being in it for over 20 years". A different standpoint.
Putting Dapper in Application layer breaks "Separation of concerns". Dapper should be in Infrastracture since it is part of external concerns.
Conceptually, I agree. But that ends up leading to indirection from App to Infra that doesn't add much in value. What's your approach there?
@@MilanJovanovicTech I prefer to keep database information out of the application. In this case, application layer knows db connection, type of db, db scheme. Pretty much everything.
You are not right with the point that presentation and infrastructure layers can reference each other. Just define an interface for what you need in application layer, then implementation in outer layers for that and it is solved. Why take shortcuts?
How will you configure it with DI?