Hi
I've been building the backend of my application (using nHibernate for data access). So far i've had some simple web-services for manipulating my data, but now I'm required to develop a web UI on for my application (using web forms). I've been looking at some different web frameworks (webformsMVP, spring.net web), and also at some client-side JS frameworks (knockout, angular), and I can't really decide what would be the best for me, and how to integrate it all. I was hoping to get some insight from you guys. I think I would like for my general workflow to be something like this:- View is created, calls its presenter.
- Presenter contacts business layer to retrieve information (which in turn contacts DAO etc.)
- Presenter returns a view-model object, which the view displays.
- User manipulates data (maybe using some AJAX to retrieve further needed information)
- View sends a view-model of the manipulated data back to presenter
- Presenter translates the view-model into a model entity and sends it to business layer now here are the parts that I find tricky:
A. How to map between view-model and model entities
I think I should use the entitie's ID to retrieve the unchanged entity from the DAO (which actually stores it in nHibernate's 2nd level cache), and perform changes on it. (another option is to store the entity i'm currently editing in the user's session. but i'm afraid that this kind of caching would create duplicity with nHibernate's cache.) B. How to translate changes on the view-model into changes on model entities I'd like to have some logic when changing model entity's properties. For example, for moving an employee from one department to another, I don't want to allow this-department1.Employees.Remove(employee);
department2.Employees.Add(employee);
but rather this:
employee.MoveToDepartment(department2);
I'm afraid this could get complicated when translating from a view-model into a model.
Any thoughts on the above two questions, and also about any client-side / server side frameworks would be appriciated. P.S. some quick background on my app: -one page of the web app displays the company's structure (departments, divisions etc.) as a tree, and allows the user to click and edit the different nodes, as well as drag-and-drop nodes to change their location. -another page displays current stock status (for each warehouse- how many products it has, how many machines are currently operativ开发者_如何学JAVAe in that warehouse etc.) - (some more pages which basically display data and allow editing...)thanks
JhonnyYou can check out Automapper for your entity mapping. Alternatively you can write your own entity mappers and entity updaters. You can then encapsulate the business logic like Move To Department in your entity classes.
Your approach sounds just fine, and I can recommend Webforms.MVP as that is a good framework for writing testable WebForms apps without rolling your own implementation.
精彩评论