I have a specification that validates codes. It looks like the following:
public ClassificationSpecification : ISpecification<Classification> { HashSet<string> codes; // constructor elided public IsSatisfiedBy(Classification classification) { return codes.Contains(classification.Code); } } The valid codes come out of a Classification table in a database. My question is, which is the better constructor for dependency injection?
public CodeSpecification(IEnumerable<string> codes) { this.codes = new HashSet<string>(codes); } or
public CodeSpecification(IRepository<Classification> repository) { this.codes = new HashSet<string>(repository.Select(x => x.Code)); } And the all important question: why?