맞춤형 모델 바인더에서 데이터 액세스를 올바르게 구현하려면 어떻게해야합니까?맞춤형 모델 바인더에서 데이터 저장소에 액세스하는 적절한 방법은 무엇입니까?
컨트롤러와 마찬가지로 IContentRepository를 사용하고 생성자에서 구현 클래스의 인스턴스를 만듭니다. 그래서 나는 나중에 IoC (DI)를 통합 할 준비가되었습니다.
이제 모델 바인더와 비슷한 것이 필요합니다. 바인더에서 DB 조회를해야합니다. 나는 컨트롤러에서하는 것과 같은 방식으로 생각하고 있지만 제안은 열려 있습니다. 바인더는 일반적으로 법인을 구속
public class WidgetZoneController : BaseController
{
// BaseController has IContentRepository ContentRepository field
public WidgetZoneController() : this(new XmlWidgetZoneRepository())
{
}
public WidgetZoneController(IContentRepository repository)
{
ContentRepository = repository;
}
...