什么情况下可以打从自定义模型绑定数据库? [英] Is it okay to hit the database from a custom model binder?

查看:258
本文介绍了什么情况下可以打从自定义模型绑定数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个对象,从HttpPost有的从数据库中获取一些数据。我想,我想允许ModelBinder的去数据库/存储库中的数据从后失踪。在实践中,这是一个好还是坏主意?

Say I have an object that gets some data from HttpPost and some from the database. I think I want to allow the ModelBinder to go to the database/repository for the that data missing from the post. In practice, is this a good or bad idea?

推荐答案

我已经决定编辑我原来的答复给我对这类事情的思维,因为已经演变2010年初

I've decided to edit my original answer given my thinking on these types of things has evolved since early 2010.

在我原来的答复,我基本上是前pressed,虽然我的直觉告诉我,你不应该这样做,我心里不舒服,说我们不应该在没有能够清楚地说明为什么。

In my original answer, I basically expressed that, while my instincts told me you shouldn't do this, I was uncomfortable saying we shouldn't without being able to articulate why.

现在,我建议你反对这个理由是一个模型绑定的责任是把用户的请求转换成一个请求模型和什么可以从请求中得到外界获取数据超出了职责范围,这

Now, I'd recommend against this on the grounds that the responsibility of a Model Binder is to translate a user request into a Request Model and that retrieving data outside of what can be derived from the request goes beyond this scope of responsibility.

这篇关于什么情况下可以打从自定义模型绑定数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆