问题
I have an application with 4 projects
Presentation
BLL
Models
DA
Should the BLL be passing and retrieving View Models to and from the Presentation Layer. (And handle all mapping)
Or rather should it only deal with Domain Models and let the Presentation Layer (Controller) handle all mappings.
Thanks
回答1:
There is nothing absolute about your development approach. you could choose what suits you in any case. But you should consider your future maintenance and extension possibilities when you choose you approach. Based on details you provided, I think you should consider some issues:
- User input verification: verification on user input isn't part of you BLL. So if you connect you presentation to BLL, you will mix both and it makes it hard to manage your code or "separation on concerns"
- In mvc case you always use data annotation for presentation. Using BLL for VM probably makes it hard to use them.
- On presentation layer, you need tools like CSS and Jquery. Using them with BLL, probably makes your code very messy and hard to maintain later.
- For any even minor change on your presentation, you need to change your BLL which is against all principals!.
- It will be hard to provide services like WebApi for clients, if you intermingled you BLL with presentation.
- BLL access from views, makes life easier for hackers!.
and lots more!.
来源:https://stackoverflow.com/questions/35306301/does-the-business-logic-layer-handle-view-models-in-mvc