這是我的情況。我的解決方案結構如下。從單獨項目中的驗證類填充MVC視圖模型
Project
用來處理路徑,顯示數據,...
Project.Core
用於處理業務邏輯,驗證,查詢,...
在Project.Core
我有我的驗證DTO(一個驗證類數據傳輸對象)。
我的驗證類(在Project.Core
):
public class IncidentValidator<T> : IValidator<T>
where T : AuditReport
{
public IncidentValidator(IList<T> ar)
{
AR = ar;
}
public IList<T> AR { get; set; }
public IList<Model> Validate()
{
var list = new List<Model>();
foreach (T ar in AR)
{
list.Add(new Model
{
IncidentId = new KeyValuePair<int, RuleType>(
ar.IncidentId,
new OccurrenceCountRule(ar).RulesValidate()
),
Circuit = new KeyValuePair<string, RuleType>(
ar.Circuit,
new CircuitRule(ar).RulesValidate()
)
});
}
return list;
}
}
我的觀點模型(Project
):
public class Model
{
public KeyValuePair<int, RuleType> IncidentId { get; set; }
public KeyValuePair<string, RuleType> Circuit { get; set; }
}
所以我的問題是,應該Project.Core
參考Project
有機會獲得我的視圖模型所以我的驗證類可以填充它?然而,我不太喜歡這種方法。我想過在我的控制器內部進行驗證,但也不喜歡這個想法。也許我的觀點模型可以在Project.Core
之內生存或者被認爲是不好的設計?
我能做些什麼?
驗證器將負責驗證我的DTO並在視圖模型中填充結果。 – Mike 2010-10-06 18:25:00