Reputation:
I've been developing a multi-tier MVC application and now reviewing what I've done so far. Especially now that I've gone back and done a fair bit of reading up again on multi-tiers/layers (there is heaps of information out there but no real consistency or standard), I'm now questioning my data layer.
I strongly suspect I have implemented it incorrectly (in line with good design) and may have gone off on a tangent. Here's what I've done:
WebUI
BLL
Includes service classes which contain:
Data
...
Stepping back, and re-reviewing, here is what I see, and what I'm questioning:
In the BLL, the EF code does not look correct here. It should be in the Data layer. Can someone please confirm?
My Data layer (i.e. Data project) contains context classes, and domain models. I've read people separate their data layer into a) DAL, and b) Models. Therefore I would guess the DAL layer would contain the context classes and data (EF) code, and the Models layer would solely contain the domain models.This would end up making you have 4 layers in total. Maybe too excessive or a good design?
Any preference where to use AutoMapper for EF to ViewModel mappings? I'm currently mapping in the Web layer, but suspect it may be neater in the BLL. Some mappings can only be done in the Web layer, such as SelectListItem for drop down lists.
Upvotes: 3
Views: 3980
Reputation: 35219
I think that using ORM (especially in code first approach) really makes separate DAL project a hassle (seriously, the DA part in ORM is nothing compared to pure ADO.NET DataReader). Instead I prefer to make a Prj.Domain
that is all about data persistence. Basically it's DAL
+Model
layers or yours combined.
The Prj.WebUI
will have it's own Models (which is better named ViewModels) which are used only as a convenient way to treat your domain data in Views.
From MVC standpoint Prj.Domain
is a Model, and Prj.WebUI
is a View and Controller.
Upvotes: 1
Reputation:
Reading up alot, this article is consistent with alot of the info out there, and answers most of my questions:
http://www.kenneth-truyers.net/2013/05/12/the-n-layer-myth-and-basic-dependency-injection/
EF code should be in the DAL, not BLL.
Moved models (out of DAL) and into it's own assembly. Now my data layer has two assemblies: DAL and Model. This may come down to personal preference. Also, I'd prefer the Web layer to have a reference to the Model assembly only, not the DAL.
I suspect I may have mappings in both the Web and BLL layers. Yet to confirm, when I get up to this.
If anyone has a better and more detailed answer, I'm happy to go with that, else this article seems to answer alot of layer related questions.
Upvotes: 2