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?