我應該如何在自定義模型活頁夾中正確實現數據訪問?在自定義模型綁定器中訪問數據存儲的正確方法是什麼?
與控制器中一樣,我使用IContentRepository,然後讓它在構造函數中創建實現類的實例。因此,我已經準備好在後期合併IoC(DI)。
現在我需要類似的模型活頁夾。我需要在活頁夾中進行一些數據庫查找。我正在考慮像我在控制器中那樣做,但我願意提出建議。
這是從我的控制器中的一個片段,所以你可以想像我是如何做它在其中:
public class WidgetZoneController : BaseController
{
// BaseController has IContentRepository ContentRepository field
public WidgetZoneController() : this(new XmlWidgetZoneRepository())
{
}
public WidgetZoneController(IContentRepository repository)
{
ContentRepository = repository;
}
...