Question

Let's say we have an application with a DAL, business layer, and presentation layer, we do dependency Inversion, and we place the database repository interfaces at the business layer.

At the data layer we use EF for database access. Who owns the entities? The business layer or the DAL?

I mean at the business layer we should already know about the entities, however the entities are generated by the data access layer. I think lower level modules should not know about higher level modules. I am really confused.

Was it helpful?

Solution

Your "domain" knows about the entities (I'm using "domain" in a broad sense here)

The business layer is part of your domain. Most of the times the DAL is also part of the domain although not from what the implementation is concerned (i.e. you have a DAL interface that's part of the domain, it's that part of your domain from where you retrieve and persist your entities; if you use EF or something else to actually do it, it's not important).

Your entities usually span your entire application. You have bussines rules and behaviours but those rules work with your entities. Those entities also reach the user in the presentation and in their knowledge of the domain (i.e. your "domain" actually models the real business domain).

Yes, lower levels should have no knowledge of the upper levels, but your entities are not owned by the upper levels, they are (most of the times) cross cutting your entire application.

Licensed under: CC-BY-SA with attribution
scroll top