Clean Architecture with ASP.NET Core 6

  Рет қаралды 388,248

dotnet

dotnet

Күн бұрын

Clean Architecture (aka Onion, Hexagonal, Ports-and-Adapters) organizes your code in a way that limits its dependencies on infrastructure concerns. Learn how to apply it to your ASP.NET Core apps!
aka.ms/dotNETC... 👨‍💻 Slides & code: aka.ms/dotnetc...
🎉 .NET 6 Release Blog: devblogs.micro...
⬇ Download .NET 6: aka.ms/dotNETC...
🙋‍♀️🙋‍♂️ Get your questions answered on the Microsoft Q&A for .NET: aka.ms/dotnet-qa
💭 Join the .NET Tech Community Forums: aka.ms/dotnet/...
🏫 Learn C#, F#, and .NET with free self-guided learning from Microsoft Learn: aka.ms/learndo...
#dotnet6 #dotnetconf #dotnet

Пікірлер: 210
@nickfotopoulos5323
@nickfotopoulos5323 2 жыл бұрын
| Links from the end of the video | ::Clean Architecture Template:: github.com/ardalis/CleanArchitecture ::eShopOnWeb:: github.com/dotnet-architecture/eShopOnWeb ::Architect Modern Apps with ASP.NET Core and Azure eBook:: dotnet.microsoft.com/learn/web/aspnet-architecture
@vinholiver6801
@vinholiver6801 2 жыл бұрын
Thanks
@mattferderer469
@mattferderer469 2 жыл бұрын
Links to the Resources Template: github.com/ardalis/CleanArchitecture eShopOnWeb Sample: github.com/dotnet-architecture/eShopOnWeb Architect Modern Apps .NET Azure eBook: dotnet.microsoft.com/learn/aspnet/architecture
@nickfotopoulos5323
@nickfotopoulos5323 2 жыл бұрын
Thanks!
@saeedtalib8358
@saeedtalib8358 2 жыл бұрын
Thank for the time and help
@rbp365
@rbp365 2 жыл бұрын
Clean Architecture Template: github.com/ardalis/CleanArchitecture eShopOnWeb Sample: github.com/dotnet-architecture/eShopOnWeb Architect Modern Apps with ASP.NET Core and Azure eBook: dotnet.microsoft.com/learn/aspnet/architecture
@Greenthum6
@Greenthum6 2 жыл бұрын
There are two fundamental issues that are often overlooked in these simplified clean architecture templates. First, UI depends on infrastructure. That dependency is usually not visible in charts for whatever reason, but it is there regardless. Secondly, the template uses core entities within DbContext in infrastructure. Now your database structure depends on domain entities. Those will evolve and your database breaks. Keeping database and domain entities separate is very important. I have used clean architecture for sometime, but in my model the core is split further into domain and application layers.
@cheesypufs
@cheesypufs 2 жыл бұрын
I agree about splitting the entity models and domain models. However this would be less necessary if you use something like EFCore migrations to ensure your DB is always updated. Although I've never been a fan of this approach, it feels fragile.
@Greenthum6
@Greenthum6 2 жыл бұрын
@@cheesypufs I haven't heard anyone using EF migrations in production and suggest nobody to do it. DBAs will not be happy. In critical systems database changes require review before apply. Keeping them in pure SQL is the cleanest approach. DbUp has been a great choice. The main issue with EF here is that it is too easy to spread database details everywhere. With clean architecture, only infrastructure layer should be responsible for database concerns. If there is only one entity through the application then everything depends on everything. Mapping objects is the necessary evil to keep consistency.
@k-ravndal
@k-ravndal 2 жыл бұрын
@@cheesypufs The main issue when using the same entity for both the domain and the db, is that you might end up in a situation where the structure or limitations of the database, also limits the way you build you domain. A database is an implementation detail, and should in no way govern the way you build your domain model.
@ApolloJKD1973
@ApolloJKD1973 2 жыл бұрын
Exactly! I have the same exact view. I use a mix of Clean Architecture and Vertical Slice Architecture (Jimmy Bogard). There are many videos on this from Jason Taylor such as this: kzbin.info/www/bejne/mnyXipVsYrGrd80 Basically all the logic is in the Architecture layer either in MediatR commands or Queries. The Application Layer and the Domain Layer combined make up the Core. The Domain Layer does not have logic for the most part. I have always found it hard to accept how putting logic in your Domain Entities is recommended. Other than the basic logic that you can put there (such as date range validations etc), we typically work with very complex logic in our applications and our Entities are used in different ways across the system. Another point where I agree with you is that no matter how much we can say we can swap out database technologies it is not easy to do. You cannot easily go from SQL and EF Core to CosmosDB without changing a lot of code! Again if your system is as simple as each Entity can save itself bla bla bla and thats it maybe you could do it with minimum coding. But that is not realistic. I have EF Core Queries that span entities and are highly complex. Good luck rewritting all that using a different technology easily!
@ApolloJKD1973
@ApolloJKD1973 2 жыл бұрын
@@Greenthum6 EF Core migrations do not need to be automatically applied to production. You can generate a SQL script from the migration and have your DBA's review and approve before you run it.
@albxdotcom
@albxdotcom 2 жыл бұрын
Thanks Steve...great work again !! I'm enjoying working with Clean Architecture, it doesn't feel like all the pieces are super glued together anymore.
@Ardalis
@Ardalis 21 күн бұрын
Exactly what it's designed for!
@Sad-Lemon
@Sad-Lemon 2 жыл бұрын
I absolutely love the shirt :D Just started watching :)
@vincidixit
@vincidixit 2 жыл бұрын
Very helpful. Well explained with examples and demo. This will definitely make things easy.
@RoggemansG
@RoggemansG 2 жыл бұрын
Thank you Steve for all these precious gifts you make for us!
@CodewithFemi
@CodewithFemi 2 жыл бұрын
Thanks Steve for taking us through this. I love clean architecture!
@caglarad2544
@caglarad2544 2 жыл бұрын
Thanks Steve for sharing your valuable information with us.
@Erril-1
@Erril-1 2 жыл бұрын
Thanks Steve! I really like Clean Architecture
@Gonkers44
@Gonkers44 2 жыл бұрын
I really don’t understand the point of the shared kernel project. I understand this was an abbreviated talk, but I don’t think that was covered well.
@steve-ardalis-smith
@steve-ardalis-smith 2 жыл бұрын
It's purely a way of sharing (high level, abstract) code between apps. If every app uses the same guard clause extensions or value object base class, or exception base class, this provides a better tool than copy-paste or sharing the same source files for achieving this reuse.
@cethrivias
@cethrivias 2 жыл бұрын
It finally clicked for me why it is called *Domain-Driven* Architecture
@omidkarami4312
@omidkarami4312 Жыл бұрын
Hi Steve, thanks so much for the amazing video, what is the best way to contact you for consulting?
@belmo_
@belmo_ 2 жыл бұрын
I didn't know that I needed this video.
@S3Kglitches
@S3Kglitches 2 жыл бұрын
this video is extremely useful and people have to realize that it is a more robust extension of three-tier architecture
@rodelias9378
@rodelias9378 2 жыл бұрын
Really awesome talk! Thanks a lot!!
@ebrimasidibeh7587
@ebrimasidibeh7587 2 жыл бұрын
Nice one 👍. I love DDD and there is always different ideas among developers about its architecture but having standard template is awesome 👌
@user-xb5qp4ok2f
@user-xb5qp4ok2f Жыл бұрын
In a different tutorial, I heard that all of MVC in a Core project was the presentation layer and that business logic should be coded in a a class library in a different project. In this tutorial (if I've understood it correctly) the presentation layer and business logic are within the Core project. At time 7:51, it states, "Model all business rules and entities in the Core project." Perhaps some further explanation can clarify this for me.
@julietchoy
@julietchoy 2 жыл бұрын
Thank you so much for putting this up!!
@jegtugado3743
@jegtugado3743 2 жыл бұрын
Awesome presentation. This reinforced my understanding of implementing DDD and Clean Architecture. Thank you, cool template.
@shatiswaranvigian9349
@shatiswaranvigian9349 2 жыл бұрын
Very helpful, thank you.
@yasharaliabbasi5653
@yasharaliabbasi5653 2 жыл бұрын
Thank you for your useful topic, How should we add authentication and authorization?
@activoutdavid
@activoutdavid 2 жыл бұрын
That's very good question. I suggest that you use standard .NET authentication and authorization and implement Policies that are implemented by calling interfaces in the Domain/Core, probably with help for example a user database from Infrastructure.
@waymanharris1284
@waymanharris1284 2 жыл бұрын
#Support #Awesome This is the most helpful youtube video I watched all year.
@PeriMCS
@PeriMCS 2 жыл бұрын
Uncle bob taught me this Clean Architecture about 20 years ago. I thought I will see something new here.
@evgeni-nabokov
@evgeni-nabokov 2 жыл бұрын
Who is he?
@viniciusmorgado9722
@viniciusmorgado9722 2 жыл бұрын
Awesome content, thank you!
@125Jackal
@125Jackal 2 жыл бұрын
Steve! How u doin? Just wanted to say that I love your courses in Pluralsight.
@baolam4180
@baolam4180 2 жыл бұрын
Thanks. Great explanation at right time for me 😍
@browaruspierogus2182
@browaruspierogus2182 2 жыл бұрын
Any and every company can manage the code as they want and according to in-house convenience standards - this is just another shuffle of someone's ambition or corporate idea that is not necessarily as good as they think
@dvanrooyen1434
@dvanrooyen1434 2 жыл бұрын
I have learnt from experience, the application/business needs should help drive the architecture and not the other way round. So for example in the industry we do say let’s make sure we have clean architecture so that we can focus the business needs rather than fighting the technology as the application grows. This has merit and is correct, but is too late in the process. Understanding the business need in a ‘clean’ manner will help getting the right architecture in place, which in turn then helps us focus on the business and all that good stuff.
@jez9999
@jez9999 2 жыл бұрын
Why is there never an acknowledgement that in order to make "clean" architecture, you introduce massive amounts of complexity? Having to learn all the new terminology for stuff like value objects, domain events, validators, custom guards, etc. and figure out how to structure it all is no mean feat, and is a lot harder and less intuitive that just creating an n-tier application, to the point where an n-tier application is probably the best choice for anything but huge projects. 21:20 Composition root in the web project. I've noticed this before. So much for "clean architecture" stopping the UI from referencing infrastructure; it has the composition root. It has to reference everything!
@Ardalis
@Ardalis 21 күн бұрын
"It's too complex!" but also "You should have added yet another project for composition root!" It's a tradeoff. Yes, you certainly *can* put all the DI/composition root logic into another project, but that only adds to the complexity without adding much value. You can certainly do that if it makes sense for your app.
@nicolasundiano8406
@nicolasundiano8406 2 жыл бұрын
if you have constants in a class Roles such as "Admin", "DemonUser", etc and you use it in all layers, where would you put this class? and the same as helpers like PaginationHelper to calculate Skip and TotalPages
Жыл бұрын
Constants to the Core project. PaginationHelper to the project where your UI lives.
@ahadporkar7355
@ahadporkar7355 2 жыл бұрын
Thank you Smith for great explanation, it's been a great help with Clean Architecture.I understand a bit better now where and how these things are handled.
@wilfredogutierrez1640
@wilfredogutierrez1640 2 жыл бұрын
Thank you for sharing, very useful
@haroldpepete
@haroldpepete 2 жыл бұрын
Great talk, it would be nice if you put a QR code next to each link in the presentation, you don't see anytihing in the description of the video in youtube about links in the current presentation, sometimes links are so large
@Ardalis
@Ardalis 21 күн бұрын
That's a great idea! I'll keep it in mind going forward.
@francogiulianopertile279
@francogiulianopertile279 2 жыл бұрын
Aweesome presentation
@UndersVzLOM
@UndersVzLOM 2 жыл бұрын
Very helpful. Where can i read more on those repository, it's base class and specifications? Thanks
@MaxBeresnev
@MaxBeresnev 2 жыл бұрын
Thanks for cool presentation and template!
@srivathsaharishvenk
@srivathsaharishvenk 2 жыл бұрын
This is one way of achieving clean architecture, this is mostly OO based, however in my view there is a much simpler way, Please see Domain Modelling made functional by Scott Wlaschin and thank me later. Everything in there can be done in any language and especially c#. The main difference is it is better not to include any IO related logic (DB, API, email sender, etc.) in the core domain layer as much as possible, even the interfaces
@steve-ardalis-smith
@steve-ardalis-smith 2 жыл бұрын
Yes you can certainly achieve similar things in functional languages. This is "mostly OO based" because C# is an OO language.
@srivathsaharishvenk
@srivathsaharishvenk 2 жыл бұрын
@@steve-ardalis-smith I guess, regardless of the paradigm, the concept is still the same, it is better to avoid IO in the domain layer as much as possible, also IMHO c# is an hybrid language these days, not just OO
@hussainhussaini2267
@hussainhussaini2267 Жыл бұрын
I don't understand something. I pulled the sample solution and see the Web project has no reference to the Core project, while it has a reference to the Infrastructure project. This not what stated in the video. In the video it's said that both Infrastructure and Web projects should talk through Core project indirectly
@lakshparab7066
@lakshparab7066 2 жыл бұрын
I think realistically it not possible to simply replace the DB without changing Domain Service logic. With proposed clean architecture the EntityFramework is now abstracted but ApplicationCore is now depend on `Ardalis.Specification` which is just a wrapper around EF and exposes EF's extension methods via Specification. For example Include(), AsNoTracking() etc which may not be suitable for different database. So if you change DB, you most probably have to change specifications and that means domain service as well.
@activoutdavid
@activoutdavid 2 жыл бұрын
As Steve mentioned, Ardalis.Specification is one of his own projects, and most Clean Architecture implementations probably don't have it unless they use his Clean Architecture template... :)
@nelsonthekinger
@nelsonthekinger 2 жыл бұрын
26:40 - I don't get the advantage of separating the specification from the repository, is it the possibility of reusing specifications over different repositories?
@nelsonthekinger
@nelsonthekinger 2 жыл бұрын
Oh and Great work with the presentation by the way
@Quasindro
@Quasindro 2 жыл бұрын
As the project grows bigger, you won't have a bloated and messy repository class. At least that's how I look at it.
@maksymkyian4920
@maksymkyian4920 2 жыл бұрын
It was great, keep doing what you doing guys =)
@muhammedshibin7786
@muhammedshibin7786 2 жыл бұрын
What if we have some , say DTOs that needs to be passed down for service implementation, where should we place them
@steve-ardalis-smith
@steve-ardalis-smith 2 жыл бұрын
"It depends". Sometimes it's really helpful to have DTOs in the Core project so everything can use them. However, most of the time these DTOs are only really used by some specific service, and aren't really a part of the "domain model". As such, they usually belong in the Web or Infrastructure project, or sometimes in a separate project (or nuget package) that these projects both reference. In that case it's usually a good idea to keep that project/package small and focused just on DTOs used for a specific purpose.
@muhammedshibin7786
@muhammedshibin7786 2 жыл бұрын
@@steve-ardalis-smith thanks
@evaldasraisutis3058
@evaldasraisutis3058 2 жыл бұрын
You say Core shouldn't have dependencies beyond shared kernel, but to implement specifications in the core project, you then have a dependency on a nugget package that provides specification abstraction, right? I realize it's a bit of give and take, but how would you navigate that decision in a new project?
@steve-ardalis-smith
@steve-ardalis-smith 2 жыл бұрын
This is a common question and sorry I didn't cover it better in the video. If you have pure code dependencies in Core or Shared Kernel, you can include them either directly within the project(s) or as NuGet references. Examples of pure code dependencies would be things like guard clauses, specifications, repository abstractions (not implementations, typically), fluent validations, etc. Basically, any dependency that simply runs in process and doesn't talk to external infrastructure concerns should be fair game.
@michaelvman
@michaelvman 2 жыл бұрын
@@steve-ardalis-smith I think Evaldas has a good point here as your specifications do have implicit knowledge of the underlying infrastructure. In your example project ProjectByIdWithItemsSpec uses the extension method Include from your Specification nuget. Use of this is obviously motivated by the knowledge EF is being used as the ORM. Of course IQueryable isn't a perfect abstraction and something like this isn't easy to reconcile with Clean Architecture, so definitely some give and take.
@steve-ardalis-smith
@steve-ardalis-smith 2 жыл бұрын
@@michaelvman It's true my Specification abstraction includes support for a .Include which can then be mapped to an EF/EF Core .Include, I'll grant that. But it's not specifically coupled to either of those frameworks (in that package - there are separate packages that are specific to EF/EF Core), and the use of .Include might be applied to other stores as well (imagine an OData backend or GraphQL building out an object graph, etc.). So, yes, I did purposefully choose to include features in my abstraction that easily mapped to my (current) implementation (because why make it hard?), but that doesn't mean I'm tied to the implementation.
@michaelvman
@michaelvman 2 жыл бұрын
@@steve-ardalis-smith I think you hit the nail on the head, why make it difficult and that's why there is some give and take. And I agree you're not coupling your specifications to a specific data store. All I'm suggesting is it's impossible for your business logic to be 100% ignorant of infrastructure concerns which is what Clean Architecture tries to aim for. Your Specification nuget allows you to use EF/OData/GraphQL features without directly coupling your business logic to those frameworks but you're still implicitly aware of how they expect to work and that's the compromise, albeit not a big one. I would be curious how elegantly specifications could be implemented when working with a data store that didn't use a LINQ interface. I'm guessing it wouldn't be possible and the heavy lifting would need to be done by a repository class. Anyway really like what you've done here and think I will try to use it as a starting point for my next project. Also very keen to give API Endpoints a spin, looks like a very promising approach.
@steve-ardalis-smith
@steve-ardalis-smith 2 жыл бұрын
@@michaelvman It is true that the LINQ-based Specification package I use (and maintain) works best with ORMs that support LINQ well. There have been efforts to apply it to Dapper and CosmosDB, for instance, that have met with limited success. The Specification *pattern* can still work with such back end stores and tools, but its implementation may need to change (for instance, if using Dapper, your specifications will likely contain raw SQL in them).
@clashclan4739
@clashclan4739 2 жыл бұрын
For complex problem give simple solution. I have seen in the name of ddd/onion/hexagonal architecture ppls tends to makes project complex to work and modify
@MostafaAjy
@MostafaAjy Жыл бұрын
Can I use database first in clean arch???? Plz help me
@primelimitt
@primelimitt Жыл бұрын
why is this not called Domain Driven Design with asp.NET Core 6? I m new to all these and it's really hard to understand what's clean architecture and what's DDD.
@mohdilyas7962
@mohdilyas7962 2 жыл бұрын
Hi, Please explain how the architecture changes when the database first approach is being followed. I didn't find much information about it as I need to implement Clean architecture with the existing database model. Please explain.
@activoutdavid
@activoutdavid 2 жыл бұрын
I think that uou need to create "clean" domain entities in Core and have your Infrastructure convert between those and your existing database model.
@Ardalis
@Ardalis 21 күн бұрын
@@activoutdavid Yes, exactly. The db first entities would need to live in an infrastructure project, and you would map to/from them, ideally. It may not be worth the effort, though...
@xustis
@xustis Жыл бұрын
Ty for video, i am not sure why if i search information about thisi find difefrent info on all sites. For example in this site we can see in the structure core, and uses cases but the most common structure is application and domain. I don't understand why microsoft don´t have a profesional template and maybe with examples and important thinks.
@tarasstrypko8160
@tarasstrypko8160 2 жыл бұрын
1. Why use custom exceptions if we can propagate Error result from operations? The problem I see with exception, that flow is a bit implicit, and sometimes it's not very easy to properly handle such exceptions. As in different places same exception could mean different things from application perspective. As an example: throw custom exception in entity constructor, have a generic handler, which catches it and maps to 400 response, which sounds not so bad, when user tries to create that entity. But, what if that exception is going to be thrown when entity is being de-serialized from cosmos, for some other operation on it (corrupted data in db)? User will get 400, when 500 should be returned. 2. Not sure I understand, why do we need Repository Interfaces in domain layer? Why can't we have them in Infrastructure layer? We're anyway going to have some kind of application layer (in your case UI project), which will glue Domain and Infra layers together. Don't we? 3. Is it real the case, that Domain layer is completely independent from DB structure? As from my experience, it was pretty hard to achieve this due to some ORM limitations or similar. Might be, I was doing something wrong. 4. You mentioned that Core project is good for Validators like fluent validation. Do you use fluent validation in your domain model? As if it's about request DTOs, then it seems more like application layer concern, isn't it? Similar question for specifications - should domain layer care about queries? Why not put them into application layer close to appropriate use-cases?
@activoutdavid
@activoutdavid 2 жыл бұрын
1. Exceptions should be for exceptional cases. If you let a Cosmos exception propagate from Infrastructure, then you can't catch it in Web or Core because they don't know what Cosmos is. But if you wrap it in a "CorruptDataException" then you can catch it in Web and return a 500 :) 2. The Web layer should not know anyhing about the Infrastructure layer. It only depends on it to setup dependency injection. So any interfaces that are used by both Web and Infrastructure must be in the Core project. 3. Yes, if you work with clean architecture you create pure domain entities and only the Infrastructure project knows what ORM you are using and converts to and from the domain entities. But you could decide to let it leak a bit into Core in your application :) 4. If you think about it, validation is actually business logic.
@AleyCZ
@AleyCZ 2 жыл бұрын
I love this!
@acp3012
@acp3012 2 жыл бұрын
I have a question, I am developing 3 microservices which is part of an application. There is a situation we use common functionalities acroess each project/layers. For example Exception handling and Entities can be used in multiple microservices. My question is where can we keep this common libraries in Clean architecture?. Do we need to have another layer that hold only common functionalities?. if we are going to have separate library then CORE, API, INFRA all layer may depend on the common library.
@activoutdavid
@activoutdavid 2 жыл бұрын
Try to reduce dependencies if you can so that each microservice can be deployed as independently as possible. I think that if you have the same entities in multiple services you should consider merging the services or slicing them differently so that they don't need to share entities. For example do not share a single database between multiple microservices. Or maybe you can actually just copy shared classes between projects.
@pedrocosta8658
@pedrocosta8658 2 жыл бұрын
Just downloaded your template, a few questions: Why do we import the infrastructure project and not the Core project in the Web project ? Also how can we call the IToDoItemSearchService interface from Web if it is defined in Core and we don't import that project in Web ? Sorry for the confusing phrasing 😅
@pedrocosta8658
@pedrocosta8658 2 жыл бұрын
i think i understand now. We do import Infrastructure because we need to add the implementations to the dependency injection container and that would be impossible without importing the project in which the implementations are. Also we import Core, it's just not appearing in the dependencies tab in my project, but we're making "using ..... core" in some pages so yeah
@alpsavasdev
@alpsavasdev Жыл бұрын
what does ardalis mean?
@jamesmclachlan2234
@jamesmclachlan2234 2 жыл бұрын
Nodding yes for 29 minutes and 57 seconds :)
@zerosandones7547
@zerosandones7547 2 жыл бұрын
should we put our Extensions in the Domain/Core project as well?
@activoutdavid
@activoutdavid 2 жыл бұрын
I suggest that you put extensions classes in the same project and namespace as the class or interface they are extending, when possible.
@zerosandones7547
@zerosandones7547 2 жыл бұрын
@@activoutdavid even if they're just strings extensions?
@diligencehumility6971
@diligencehumility6971 2 жыл бұрын
Is it doable to use this pattern with Azure Functions?
@mart0347
@mart0347 2 жыл бұрын
Yes. If you are using DI with your function then you may use CQRS.
@nateg247
@nateg247 2 жыл бұрын
I was thinking the same and somehow not completely convinced. Some concepts can be applied though
@diligencehumility6971
@diligencehumility6971 2 жыл бұрын
@@nateg247 I am not sure if Functions should be seen as microservices, and thus your functions have to communicate with each other. Which seems silly. Instead of having the data access in the stomach of your application. Was thinking using MediatR, and simply inject MediatR into the Functions projects. Is this doable?
@mart0347
@mart0347 2 жыл бұрын
@@diligencehumility6971 Yes!
@diligencehumility6971
@diligencehumility6971 2 жыл бұрын
@@mart0347 But doing it this way, my Functions project will have a reference to my Application project, which will be a DLL with all my functions. A single Azure Function is meant to represent one controller in traditional api right? So I might have a Product Functions project, which have get/post/delete/put methods for Products right?
@dotnetlearnyourself2298
@dotnetlearnyourself2298 Жыл бұрын
Nice Video
@cburys
@cburys Жыл бұрын
regarding the diagram at 6:44 and how everyone says dependencies should flow towards the core project, doesn't the core project have to import the infrastructure project? Are y'all saying it's not dependent on it simply because the interfaces for the services and models are defined in in the core project?
@yuvarajvelmuruganmudaliyar
@yuvarajvelmuruganmudaliyar Жыл бұрын
Domain layer is the CORE and it doesn't depends on anything else. The core contains domain/business models and domain/business logic.
@Ardalis
@Ardalis 21 күн бұрын
@@yuvarajvelmuruganmudaliyar Correct. It uses the Dependency Inversion Principle such that interfaces are defined in Core/Domain project but implementations are in Infrastructure project.
@Siuari1
@Siuari1 2 жыл бұрын
So, if i have to implement a TokenService that has external dependencies like microsoft jwt packages, for exemple. My question is: Will it go on infrastructure?
@activoutdavid
@activoutdavid 2 жыл бұрын
If the tokens is used in Infrastructure for calling an API then the TokenService also belongs in Infrastructure. Tokens are probably not part of the Domain/Core.
@c-sharptricks9899
@c-sharptricks9899 2 жыл бұрын
ls this architecture good for microservices? please respond anyone who have used it or can provide a best link for that purpose. Thanking you in advance..
@jaanustilk2769
@jaanustilk2769 2 жыл бұрын
So Web actually depends on Infrastructure not on Core. I dont see this as a problem but I dont understand why this is not clearly stated in the video.
@pedrocosta8658
@pedrocosta8658 2 жыл бұрын
but do you understand why ? I mean in the Web project we wanna call business methods, not infrastructure right ?
@activoutdavid
@activoutdavid 2 жыл бұрын
Web depends on Infrastructure because it needs to setup dependency injections for Infrastructure. But it may not call directly into Infrastructure :)
@kostasgkoutis8534
@kostasgkoutis8534 2 жыл бұрын
Haha, love the T-shirt
@M4tt1mus
@M4tt1mus 2 жыл бұрын
The examples of going with Clean in the beginning are just examples of general bad architecture or don't give you much. For example, Business Logic in the DB is frowned upon by all modern architecture approaches, no?
@user-sn6vo8fr8g
@user-sn6vo8fr8g 2 жыл бұрын
Thanks
@user-ng8ph5jm8w
@user-ng8ph5jm8w 2 жыл бұрын
Thanks for such interesting talk! But how in this architecture we should call business logic from webapi?
@Ardalis
@Ardalis 21 күн бұрын
Ideally business logic lives in Core/Domain project. Web API gets to it via Application Services or by sending messages (Commands, Queries) via MediatR which are handled in an Application or UseCases project. The application services/handlers use the domain model types along with persistence abstractions to do the work and persist any state changes.
@ADSNGreenLife
@ADSNGreenLife 2 жыл бұрын
What about If I want to create Microservice and inject it where should I do that? Can we have Angular template with clean architecture ?
@activoutdavid
@activoutdavid 2 жыл бұрын
You can implement a microservice according to Clean Architecture. If you are calling other microservices you do that from the Infrastructure project.
@ADSNGreenLife
@ADSNGreenLife 2 жыл бұрын
@@activoutdavid thanks David for clearification.
@ADSNGreenLife
@ADSNGreenLife 2 жыл бұрын
@@activoutdavid How about If we want to host on azure. Few are Azure Function and Rest api then are we going to publish separate in projects and host it? is it so ?
@gijduvon6379
@gijduvon6379 2 жыл бұрын
Sorry, but this template is really mess! Repository calls in controller, specifications, ifelses. Nothing clean found....
@pablocom
@pablocom 2 жыл бұрын
lovely tshirt xD
@sergeiburtsev5712
@sergeiburtsev5712 2 жыл бұрын
The topic's architecture as I see it: let's have a big monolith in the center and surround it with some helper projects that will help it work somehow.
@steve-ardalis-smith
@steve-ardalis-smith 2 жыл бұрын
If you think a domain model with no dependencies on UI or data or other infrastructure is "a big monolith" then I could see how you might arrive at this conclusion. However, a domain model is, in fact, just a class library, not a monolith.
@sweeperq
@sweeperq 2 жыл бұрын
What do you do when you have items in your domain that depend on Identity Users? For instance, an e-Shop may have an Order table with a reference to the User Id that placed the order. If I want to view all of the orders for a single user that works just fine *var orders = await context.Orders.Where(x => x.UserId = 10).ToListAsync()*. However, if I want to show a list of orders with associated user details (name, email, etc), all of a sudden I have 1 + N queries because the Identity User is in the Infrastructure class and our other entities cannot reference it. For instance, we cannot do _var orders = await context.Orders.Include(x => x.User).Where(x => x.User.LastName = "Anderson")_ because introducing User would create a circular dependency between the Domain and Infrastructure layers.
@hakoningvaldsen8046
@hakoningvaldsen8046 2 жыл бұрын
You can not in any way depend on Identity User in Infrastructure from Core. You would need to have an Interface in Core representing the Identity and let Infrastructure implementation map and inject into Core. You could then replace your Identity system completely, as long as the new system can map to and honor the Interface of Identity in Core. This is the whole point, and where the cleaness comes from.
@Ardalis
@Ardalis 21 күн бұрын
For raw queries I would typically avoid trying to use the domain model (which is built for mutations/updates) and instead just execute a database query directly. In many cases the identity information will be on a separate database or somewhere else entirely (for instance, Okta, Azure Entra, etc) so it may make sense to have a local *materialized view* of the user information you wish to display, which is periodically updated from the actual source.
@burakgozen8932
@burakgozen8932 2 жыл бұрын
Can anyone help me with migrations in this example?
@nonamezz20
@nonamezz20 2 жыл бұрын
Where would you place a hosted service ?
@activoutdavid
@activoutdavid 2 жыл бұрын
The IHostedService or the BackgroundService are implemented either in the Web or the Infrastructure project depending on the circumstances, but that implementation can then use domain logic in Core.
@angmathew4377
@angmathew4377 2 жыл бұрын
Hi Everyone, @here can I have some thing similar for Node.js and express?
@rahulsen002
@rahulsen002 2 жыл бұрын
Under what situation will I ever use SQL lite in an environment, SQL server in another and cosmosdb in prod
@RajaKajiev
@RajaKajiev 2 жыл бұрын
1 - local dev testing, 2 - prod on premise, 3 - cloud-hosted deployment ?
@turn1210
@turn1210 2 жыл бұрын
Yeah, that sounds like an accent waiting to happen
@pauloperovic5683
@pauloperovic5683 2 жыл бұрын
not using miscrosoft edge? ccc :P
@nothingbuthardwork8336
@nothingbuthardwork8336 2 жыл бұрын
Did someone know what kind of tool he use for zooming and drawing the red arrows?
@bobmcbob4399
@bobmcbob4399 2 жыл бұрын
ZoomIt I believe.
@ram62836
@ram62836 2 жыл бұрын
Why API contracts are not within core?
@kaasbaas9532
@kaasbaas9532 2 жыл бұрын
application logic != domain logic
@PhantomAxxaxxin
@PhantomAxxaxxin 2 жыл бұрын
Prefer Vertical Slice Architecture by Jimmy B.
@CoricComPlus
@CoricComPlus 2 жыл бұрын
9:16 ahaha ))) see the image at the bottom. Does Steve ever visited gym? )
@Ardalis
@Ardalis 21 күн бұрын
I have a small home gym - does that count?
@HeitorGiacomini
@HeitorGiacomini 2 жыл бұрын
DotNetCoreWeb have a reference to Infrastructure. Why?
@activoutdavid
@activoutdavid 2 жыл бұрын
To setup dependency injection
@Ardalis
@Ardalis 21 күн бұрын
@@activoutdavid Yes, just for convenience. You can move composition root to another project if it really bugs you or you need to keep that separation "pure".
@jayakumar2927
@jayakumar2927 Жыл бұрын
your github roject shows always unloaded all projeccts
@clashclan4739
@clashclan4739 2 жыл бұрын
I totally disagree with aggregate root concept. There can be multiple scenarios i just have to crud on depended entity like order details without a need of aggregate root. Then why forcing it in the name of ddd
@Ardalis
@Ardalis 21 күн бұрын
Like all patterns, use it when it's useful.
@duongkytruong
@duongkytruong 2 жыл бұрын
tks
@prendas52
@prendas52 2 жыл бұрын
that template works in VS code?
@Ardalis
@Ardalis 21 күн бұрын
Of course. It's just a solution file and projects...
@gibran800
@gibran800 2 жыл бұрын
Awesome!
@mishashins
@mishashins 2 жыл бұрын
I used ur architecture its hard but its funny
@dmitrynenazhenko209
@dmitrynenazhenko209 2 жыл бұрын
I use Clean architecture for my project, it is a little bit different though and even less depend on each layer. However using Value Objects is a real pain in the ass. First of all if you create your domain model and use it as main entity you can only guarantee that your value objects will be validated during Insert/Update requests from front-end. If you are trying to build your domain entity from external dependency or even from database request you may not guarantee that your Value Object will match the data that you got and it will break with validation. If external service that you are relying on return you something that you are not expecting, your application will fail on the stage of building that Value Objects
@nyonor7314
@nyonor7314 2 жыл бұрын
Builder pattern в помощь?
@activoutdavid
@activoutdavid 2 жыл бұрын
I think that in this case you should have a separate entity (call it DTO or API Model if you want) in Infrastructure without the value objects, and then you write code to map from the infrastructure entity to the domain entity and handle validation errors.
@Petoj87
@Petoj87 2 жыл бұрын
While I loved this, it was a bit rushed
@OeHomestead
@OeHomestead 2 жыл бұрын
Nice, but wow, that's really, IMHO, making things way too complex for normal projects.
@vasilymeleshko
@vasilymeleshko 2 жыл бұрын
Если честно, ничего нового, для солид решений это называлось платформенными сборками разделенными по зонам и уровням ответственности.
@rahulmathew8713
@rahulmathew8713 2 жыл бұрын
Your database and related should be a separate solution and a microservice else its not reusable . Now only your web app can call it. If I want a mobile app and thats wants to call the same dal then. Should I reinvent wheel again, wasting companies time for redoing whatever we did to build those db related things.
@botyironcastle
@botyironcastle Жыл бұрын
this is not clean arch this is technical layering
@DigitalNomadOnFIRE
@DigitalNomadOnFIRE 2 жыл бұрын
Fall into the pit of success LMFAO...
@halivudestevez2
@halivudestevez2 2 жыл бұрын
is it clean? not for me :D
@yesubabu2880
@yesubabu2880 2 жыл бұрын
Great explanation..thanks for confusing me..did not explain well..But u r a good developer not a good presenter
@Philinnor
@Philinnor 2 жыл бұрын
It's hard to trust someone not using dark theme.
@Ardalis
@Ardalis 21 күн бұрын
I normally do but not for presentations since light theme is often easier to see in different lighting conditions.
@ВиталийБулдаков-ш4э
@ВиталийБулдаков-ш4э Жыл бұрын
So bad I can't like it twice
@andrewsoldan6050
@andrewsoldan6050 2 жыл бұрын
Overthought, overused, unnecessary complex, ugly - I hate today's IT after 20 years in the business. LOL
Clean Architecture with ASP.NET Core 7 | .NET Conf 2022
27:58
Clean Architecture with ASP.NET Core 8 | .NET Conf 2023
29:17
Magic or …? 😱 reveal video on profile 🫢
00:14
Andrey Grechka
Рет қаралды 69 МЛН
Running With Bigger And Bigger Feastables
00:17
MrBeast
Рет қаралды 214 МЛН
POV: Your kids ask to play the claw machine
00:20
Hungry FAM
Рет қаралды 13 МЛН
8 await async mistakes that you SHOULD avoid in .NET
21:13
Nick Chapsas
Рет қаралды 312 М.
Visual Studio Live! @ Microsoft HQ 2024 - Thiago Almeida
53:13
VisualStudioLive
Рет қаралды 34
New Blazor WebAssembly capabilities in .NET 6
29:11
dotnet
Рет қаралды 98 М.
Languages & Runtime Community Standup - What's new in F# 9
1:04:28
10 C# Libraries To Save You Time And Energy
33:59
IAmTimCorey
Рет қаралды 206 М.
.NET Framework vs .NET Core vs .NET vs .NET Standard vs C#
25:14
IAmTimCorey
Рет қаралды 553 М.
Magic or …? 😱 reveal video on profile 🫢
00:14
Andrey Grechka
Рет қаралды 69 МЛН