Search code examples
validationclassinterfaceenterprise-library

Enterprise Library Validation Block - Should validation be placed on class or interface?


I am not sure where the best place to put validation (using the Enterprise Library Validation Block) is? Should it be on the class or on the interface?

Things that may effect it

  • Validation rules would not be changed in classes which inherit from the interface.
  • Validation rules would not be changed in classes which inherit from the class.
  • Inheritance will occur from the class in most cases - I suspect some fringe cases to inherit from the interface (but I would try and avoid it).
  • The interface main use is for DI which will be done with the Unity block.

Solution

  • The way you are trying to use the Validation Block with DI, I dont think its a problem if you set the attributes at interface level. Also, I dont think it should create problems in the inheritance chain. However, I have mostly seen this block used at class level, with an intent to keep interfaces not over specify things. IMO i dont see a big threat in doing this.