I have a ASP .NET WebApi and a Web Project. I'm about to create a DAL class library... Which will be my codefirst/POCO's or possibly edmx files.
I'm wondering do I need to have another class library for DTOs of ViewModels?...
I'll need to map db entities to some sort of ViewModel that will probably be needed by both the web and Api projects.
Does this sound right?
1 Answer 1
Surprisingly, it depends.
If we're talking about a small project with a small number of model entities, then there's no sense in introducing another dummy level of models.
But in bigger solutions, especially when DI (dependency inversion) will be introduced between DAL and BL, it's helpful to separate (or even necessary) to create a DTO objects. This separation will allow you to break dependency between Web projects and DAL layer and increase testability.
Some DTOs will be very similar to db entities, so using an Automapper
may be handy.
-
In my DAL library would it make sense to keep the ef POCO's, ViewModels and Repositories? As long as the Web, and API projects can both use the DAL and have access to ViewModels I think it should be okraklos– raklos2016年03月15日 22:58:11 +00:00Commented Mar 15, 2016 at 22:58
-
How big it gonna be finally?andrew.fox– andrew.fox2016年03月16日 06:53:17 +00:00Commented Mar 16, 2016 at 6:53
-
not massive, just my own project at the momentraklos– raklos2016年03月16日 09:02:27 +00:00Commented Mar 16, 2016 at 9:02
-
so you should be ok with option a), id est, using domain entities in web application with ad hoc viewModels where necessary.andrew.fox– andrew.fox2016年03月16日 16:29:34 +00:00Commented Mar 16, 2016 at 16:29
Explore related questions
See similar questions with these tags.