开发者

problem with error handling of c# application

开发者 https://www.devze.com 2023-04-03 19:58 出处:网络
i\'m implementing bulltain board(or forums) for my website and i\'m using MVP pattern in c# and asp.net along with a typed dataset to connect to the database. my problem is that i\'m not sure where sh

i'm implementing bulltain board(or forums) for my website and i'm using MVP pattern in c# and asp.net along with a typed dataset to connect to the database. my problem is that i'm not sure where should i handle the possible errors and validat开发者_如何学Pythone the incoming/outgoing data. i came up with two different solution:

solution 1:

view: do nothing just pass the data to presenter

presenter: validation and error handling related to model, database and the view

model: do nothing just return data or error from database

solution 2:

view: validation and error handling related to pages and user inputs

presenter: do nothing just be the mediator

model: validation and error handling related to database and model`

so which solution is a better approach??


I woulds personally stand for second solution for

view: validation and error handling related to pages and user inputs

this. As it's important for simple (f.e typing errors) give the user immediate feedback, not making him wait for response from the model.


I'd absolutely recommend solution 2.

Validate as much as possible in the view, so that most of the time the user can expect the interaction to succeed, once they send the data. Validate again in the application to filter out invalid and/or manipulated requests and apply domain specific rules.

Please remember that, since MVP is a UI pattern, the model is just data containers assembled by the presenter. Domain model, business logic, database access and therefore the ultimate validation should be located underneath the MVP-based UI layer in the application itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号