Get the source code for this video for FREE → the-dotnet-weekly.ck.page/ca-from-scratch Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
Thanks for the video! It is important for beginners to know that once you get a hold of separating stuff you can adapt this structure to your case. Merge and rearrange. Even create your own modules and so. In my case I moved more towards a VSA and put controllers together with application code. As long as you clearly keep stuff logically separate it is OK.
Hi Milan, thanks for this insight into the basic project setup which has been born out of experience. Just embarking on a new project and I am adopting DDD, CQRS and MediatR as having worked on a legacy project for the past 10 years I can see the benefits of this approach and I look forward to future videos!
Thanks for sharing! There are some details that I would like to understand there... - As why do you have separate WebApi and Presentation layer? - Why is Application layer separate from Domain layer? Keep making great stuff!
In theory, domain can be shared by many applications [because It depends on nothing] But, if that's not the case, create a Core project and put both your entities and your use cases in it. :)
1. It's a personal preference of mine. Separating the executable (WebApi) from the endpoints/controllers 2. You want to isolate the core domain, so that it's not polluted by external concerns
@@MilanJovanovicTech hmm isn't application layer as well your core domain (logic). By doing that you're somehow breaking YAGNI with the assumption that your domain will have different applications. Thanks for clarification!
Clean architectur subjective, so it's different for a lot of people. Personally Mine is as Fellows(Folder structures) Sol-Folder Entities Services DTO(AddReq/EditReq/Res for each Entity plus some custom ViewModels) Interfaces Helpers actual Services..... Main Project areas(if req)
Great video, I am trying to convince work to convert one of our solutions to implement the CLEAN architecture and this video has helped me focus my thoughts.
Oh man :) Yesterday I've created a CQRS + Clean architecture web API. I went back and forth on your videos to structure the project :) I wish I had waited one more day :)
I would disagree on a few points.. 1. The WebAPI project is your presentation layer, you do not need a separate "Presentation" project. 2: Logging wasn't relevant to the video but it should be abstracted to an ILogger and it's implementation should be moved to the infrastructure project. Obviously, these are just my opinions. Your videos are some of the best on RU-vid for these topics.
1. Agreed, but this was about controlling direction of dependencies (if one needs it) 2. You can still use ILogger with Serilog | Obviously, these are just my opinions As are mine 😅 Most software engineering is opinionated.
Great one. Could you please extend this video and show us one step further such as how we can add a helloworld endpoint that will fetch data from db and return json response. Basically we wanted to learn where to plant view models, where to put services, where to put repository and make it workable.
I think splitting the infrastructure layer to multiple projects for each infrastructural concern (database, email gateway, other external apis) looks more maintainable. I did that in a few projects and helped me better organize and understand my codebase (inspiring from the "screaming architecture")
I would imagine the decision to use a clean architecture or other alternative is a decision for the development team. Surely the solution architecture shouldn't be so prescriptive as to dictate implementation detail like how to organise source code?
Solution architecture is one level above this, so it would be just a component. C1/C2 diagram perhaps, check it out. For something lower level than that, you can do C3/C4.
I'd be interested to see why you seperated WebApi and Presentation. I don't see the point at first glance >) But thanks for your service in this community! Love this channel so much.
Nice video, thanks. Still eagerly awaiting your video on setting up a modular monolith with module registration. Perhaps you could use this video as a starting point by showing how to register two CA projects?
I think yes, this video will be a starting point, to a more complete series about CA. And then I plan to evolve it into Modular Monolith. But honestly, Modular Monolith is such a complex topic that it would probably be better off creating a detailed course about it (4-5 hours) and just explaining absolutely everything.
Great Video simple and Clean :) Good idea will be to record comparison of clean architecture approaches of ardalis vs jason taylor template. One more idea maybe to record one without use of CQRS and MediatR in the Application layer. keep up the good work pozdrav iz Makedonije :)
Two things I didn't understand so far: 1. What's the purpose of having a "Presentation" project additionally to the "WebApi" project? So far, I was used to have only the WebApi project. What would you put into the Presentation project? 2. Why did you add Serilog.AspNetCore to the WebApi project and not to the Infrastructure Project? Isn't logging an infrastructure-related topic?
1. Move the API endpoints/controllers into that project, along with any view models. More of a personal preference than a real necessity. 2. Ah, good point! I find it easier to leave Serilog registration there because of the tight ASP.NET Core coupling (registering on the HostBuilder). Of course, we can move all of the registration into AddInfrastructure. Now that I think of it, it makes perfect sense. Thanks for calling me out on that 😁
finally i land on the noob section please guide me into clean architecture. The Clean architecture and DDD series need to start from this vid😆 btw my VS not auto adding the using statemet :/ how do you do that ?
No, You just mentioned that we have two options on how to structure the presentation layer, but didn't mention the benefits of separating the presentation into two projects. 😔
As I understand Prestentation project is a bridge to Application -> Domain and can consist of ViewModels/Models for WeApi/Razor Pages projects? At the same time there is a separate path from Api to Infrastructure -> Persistence which do not interfere with Application/Domain projects.
Great video, I guess for the unit tests, it will be in another project right? in this case, a unit test project? what references from the other projects should have this unit test?
Have you or anyone implemented clean architecture in older versions of the .NET framework? The company I work for is still programming using this framework and it looks to me that we could also benefit from clean architecture also so I'd like to explore this possibility. It will be a plus of course if this has already been done to see how to approach this. Thanks
I can't remember the last time I used .NET Framework 😅 The biggest hurdle will be having a proper DI container to use. Everything else should be the same.
Thank you for this educational video that you sent. Do you have an example of a website or a small project that can be implemented and that I can understand the concept of this method and standard for me to check, or have you made a training video on this matter so far? Thank you.
Thanks for the video. In some tutorials, there is no Presentation layer. And the REST Controllers, for example, are in the Application layer instead of Presentation layer. Do you have any thoughts on that, is this also valid ?
Both approaches are valid, imo. Depends on how much control you want to have over the Controllers and what they can access. One example where it makes sense to separate the endpoints is when building a Modular monolith.
@@MilanJovanovicTech yeah make sense. Actually couple of year ago i heard on internet that is only good for development environment it would suck on production real world apps So i wasn’t sure about it, although i like it very much as it keeps code highly clean, readable and maintainable!
The purpose of dependency injection is not to give you default settings which you then can use (the DependencyInjection class you created in backend/application layer) but that you inject the dependencies and settings on your own. This means that from the REST API project, you should be configuring the whole backend, no?
Пре свега, свака част за труд. Пратим те већ неких месец дана и могу рећи да снимаш прилично квалитетне садржаје. Шортове, које радиш, редовно пратим и искрено, одличне типс-енд-трикс објављујеш. Свака част. Успут, срећан МВП. Елем, као особа која се бави овим послом 13 година, имам једно питање за тебе: Где си купио ону лаву на полици иза :)
Thanks but ideally, as expected in Clean Architecture of Uncle Bob : the Application Layer should be TECHNOLOGY AGNOSTIC, so in this layer : no dependency injection Tool, no Mediatr, and so on. All of this should go into the Infra Layer !
I was very confused when I heard that the presentation layer could be a REST Web API. In this case, which layer does my frontend built-in React that consumes this Web API belong to?
Thank you for your video. Best explanation I've found. I have a question. Is it correct to the WebAPI layer know about Infrastructure Layer? Some diagrams in the internet show that Application and Domain Layers only work with Infrastructure layer
Hi Milan, thanks for the video! I have just one question though, why didn't you reference application project in infrastructure project? (PS: I am new with clean architecture concepts)
@MilanJovanovicTech Thanks for giving us this wonderful video. Also I have a question, when I go to register the "AddPresentation()" or "AddInfrastructure()" or "AddApplication()" inside the program.cs file, it gives me an error : 'IServiceCollection' does not contain a definition for 'AddPresentation' and no accessible extension method 'AddPresentation' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)'. Also, I have references all three projects inside the WebAPI project.
@@MilanJovanovicTech I need to implement CQRS in another language. So i like to know which CA layer emits(i guess application layer) and which CA layers listen to the command and query. pls pardon my ignorance on CA on this aspect as I am trying on the same
Hey Milan, first of all I like very much your videos :). Lately I also feel that the infrastructure indeed should be split in more parts like you did in your presentation: Intrastructure and Presentation and I have a question regarding this or at least I need confirmation for my thoughts :). For the case when I have an Api and a Cli built on top of my whole application then my infrastructure layer would be split in 3: Infrastructure (with core infra stuff), Presentation.Api, Presentation.CLI or? Thank you
I'd say the Infrastructure is irrelevant here. And the real question is Presentation - should we split it in two? If the entry points are different, and it looks like they are, then it makes sense
Hi Milan! Thank you for the video. You pasted in the configuration for Serilog but there is a long line that is not visible towards the end. Can you share the whole code elsewhere please?
Thanks for the video. Can I create a web application that use that api directly or should i use web application controllers to call this api by client clases for example? If i can use it direcctly i am not sure if domain should contain logic like ViewModels, resources, etc. Very difficult to find Api with ddd and web application integration, everybody only talk about the api and i am so confused.
@@MilanJovanovicTech thanks for your reply, really appreciate it. I'm trying to wrap my head around this properly. Would use cases/ business logic that span several aggregates interfaces and implementation both sit in application layer? Should those go in the same folder? I'd like see some good examples of this. Adding to this question would an entities IRepository be in a shared entity folder in the domain layer and then implementation be in the persistence layer? Then my use case services interface and implementation would use those repositories and sit in the application layer?
When would you want to use this design over modular monolith? In the end both seems to be more favored to bigger monoliths rather than small microservices.
@@MilanJovanovicTech Would be a lot of projects in that single solution :) lets say you are using clean architecture and need to introduce some background processing like azure functions, for this its common you need to share code and entities. Would that function app reference the same app/infra project or how would you go about this?
Thank you for your useful tutorial. I have a question regarding the Presentation layer what is the difference between it and the WebApi project? and in case I have a project consisting of several presentations such as gRPC, WebApi, MVC, etc., what is the good way to handle all of them in a single project?
WebApi is the composition root, and it brings them all together at runtime. Presentation is there to define the endpoints (entry points). You can move the Presentation into WebApi.
Where are the optionsetups added to the iservicecollection? All in application so that infrastructure and persistence can make use of them in their dependency injection class?
Thanks! Btw for anyone who was wondering about thjs. For EF it provided a provider to get the service options when declaring the options config (Milan shows that in a vid). But I found if that wasn't available I'd declare the options config with the setup class then use the buildservicdprovided method then with that get the options class I just binded to.
hey milan!! I saw your serilog video and implement serilog in my project. its great.. but i need logs to print in seperate folders for each controller. can you please help me out or make another video about serilog with indepth configurations. thanks 👍
When writing for example a microservice or another type of project when all the business logic can only be exposed by webapi calls: I like handling all the validation as a middleware for webapi controllers or minimal APIs. That way your services/CQRS handlers and even domain classes do not need to be populated with validation and checks like the length of the email, etc
Shouldn't logging be configured inside the infrastructure layer ? I've seen CA aproaches using Serilog this way. Is it more optimal to configure it inside the API layer on .NET latest versions?
Within this example video, does the Presentation Layer Reference the Application Layer (MediatR Nuget was added into the Application project). ? Nice vid.
You mentioned that the API doesnt need to import the domain layer, because it will implicitly get it from the application layer, what do you mean by that, when the application layer doesnt hold the domain logic. Was this something you did not meant to say, or could you elaborate on what you mean. Right now my API needed to import also the domain layer, since thats where the models, exceptions etc are stored. But if you have a way to get to the domain from application, I am all open minded.
I still don't get why you would create a presentation layer if you're creating a web API project. I understand it is the entry point and you will register your controllers in the web API project but why? Why not do everything in the web API project?