Here is my situation. My solution structure is as follows.
Project Used to handle routes, displaying data, …
Project.Core Used to handle business logic, validation, querying, …
In Project.Core I have a validation class that validates my DTO (Data Transfer Object).
My validation class (in 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;
}
}
My view model (in Project):
public class Model
{
public KeyValuePair<int, RuleType> IncidentId { get; set; }
public KeyValuePair<string, RuleType> Circuit { get; set; }
}
So my question is, should Project.Core reference Project to have access to my view models so my validation class can populate it? I don’t really like that approach however. I’ve thought about doing the validation inside my controller but don’t like that idea either. Perhaps my view model can live inside Project.Core or is that considered bad design?
What can I do?
If this validator class is intended to validate view models, then you should put it in the same project as the one containing your view models. Another possibility is to externalize your view models into a separate assembly which you reference in
Project.Core(the first approach seems better though). You shouldn’t referenceProjectinProject.Corein any case.