In my program (a console application that does edit and imputation of data) I give the user the ability to provide a data dictionary in a number of different ways: tab-delimited text files, Excel workbooks or in a database. The dictionary consists of several (12-15) files/sheets/tables. I am trying to come up with a nice way to load the data from the various sources into the database.
My solution thus far has been to use a repository to isolate the various data sources and have these repositories spit out DTOs that I map onto my domain model. I use the Builder pattern to control the entire sequence of events.
Basically the sequence of events for each file/sheet/table is:
- Get the DTOs from the repository
- Validate the information in the DTOs
- Then
- If the data is good, map the domain entity
- else keep a running list of errors.
My question is this: I am trying to figure out where the best place is to validate the information in the DTOs? One possible solution was to add an interface on the DTOs like so
public interface IValidate
{
void Validate();
bool HasErrors { get; }
IEnumerable<string> GetErrorMessages();
}
is this too heavy for a DTO? Should the validation happen somewhere else? Sorry if this is a little subjective.