Domain Driven Design Entity Framework Example
Watched a tutorial by pluralsight in which they mention repositories and noticed that a repo normally contains basic crud operations create update fetch remove entity.
Domain driven design entity framework example. Nothing much was explained with regard to entity framework. Object relational mapping and domain driven design are two orthogonal concerns. This article is about why ddd is useful with a database and how you can implement a ddd approach to data persistence classes using ef core. In domain driven design it s common to keep business logic in a rich model.
Take for example my domain as poco. The application is available as of december 2010 as net port. This happens when the logic we re trying figure out where to put doesn t involve one entity in particular there are cases where it s ok like our job example utilizing the question entity but there are other cases where the two entities involved shouldn t necessarily know about each. Here is the relevant content from the email.
Sometimes it doesn t feel natural and doesn t make sense to put certain domain logic inside of an entity. It turns out that the ef creators wanted to. The team hopes that beyond concretely demonstrating ddd in a conventional system the example can become a platform for experimentation with new technology and innovative approaches. Here are some thoughts on distinctions between aggregates and entities in domain driven design ddd in response to some good questions harry brumleve asked me via email.
An entity as defined by ef concretely means any object that you wish to map some subpart of your relational model to and from. An orm is just here to bridge the gap between the relational data model residing in your database and an object model any object model. My goal is to allow my domain models that get persisted with ef contain some logic within them. Please pardon my ignorance but based on the above info it s either entity framework isn t adequate for domain driven design or the domain driven design is an imperfect and obsolete approach.
I am building an application using domain driven design that is using entity framework. This article is about how to apply a domain driven design ddd approach to the classes that the entity framework core ef core library maps to a database. Out of the box entity framework is pretty nonrestrictive as to how entities get added to the graph and then persisted. On my article creating domain driven design entity classes with entity framework core ardalis commented that your entities all are tightly coupled to ef core.
The functionality is based on the cargo example used in eric evans book. Then i did a podcast with bryan hogan where we discussed domain driven design ddd and he goes further than my crud only create read update and delete approach he says that the entity classes.