Skip to content

Why is the infrastructure layer using the domain objects from the core layer as models for DbSets in the DbContext? Doesnt that defeat the whole purpose? #716

Answered by ardalis
nabeelfarooqui98 asked this question in Q&A
Discussion options

You must be logged in to vote

I agree with @lukehammer.

Why do we directly leverage the domain model classes from Core via EF DbContexts in Infrastructure? Because we can, with no ill effects! EF Code First is a feature they added many years ago specifically because developers wanted this capability. Prior to that, one would have a DbContext which had its own models, and you would need to map them manually to your domain model, and it was just one more set of mappings that didn't really add any value.

Now, if you don't own your database, which means you don't have a DDD bounded context, then you may find value in having a separate persistence model in your infrastructure code. Why? Because you want your domain model t…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@nabeelfarooqui98
Comment options

@lukehammer
Comment options

Comment options

You must be logged in to vote
3 replies
@lukehammer
Comment options

@nabeelfarooqui98
Comment options

@ardalis
Comment options

Answer selected by nabeelfarooqui98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants