我应该如何在我的自定义模型绑定器中正确实现数据访问?
就像在控制器中一样,我使用 IContentRepository,然后让它在构造函数中创建其实现类的实例。所以我已经准备好在稍后阶段合并 IoC (DI)。
现在我在模型活页夹中需要类似的东西。我需要在活页夹中进行一些数据库查找。我正在考虑像在控制器中那样做,但我愿意接受建议。
这是我的一个控制器的一个片段,所以你可以想象我是如何在其中做的:
public class WidgetZoneController : BaseController
{
// BaseController has IContentRepository ContentRepository field
public WidgetZoneController() : this(new XmlWidgetZoneRepository())
{
}
public WidgetZoneController(IContentRepository repository)
{
ContentRepository = repository;
}
...