Where do you put validation on projects using Driven Design?

Where should I put the logic for checking domain objects in my solution? Should I put them in the classes Domain, Business layer or something else?

I would also like to use this application block and policy implementation block from the Microsoft Enterprise Library.

What validation strategy should be used to fit all this well?

Thanks to everyone in advance!

+3
source share
4 answers

It depends. First, you need to understand what you are checking.

You can confirm:

  • this value that you extract from the Http message can be parsed as a date,
  • that Customer.Name does not exceed 100 characters,
  • , .

- , . (. " arent created equal" ).


Thing , , .

, , , .

, , .

- . .

+5

.

, , , . , ( ). . , , (DRY). , .

( DI, , - ), (, , , , , - , ). ( , , , , ), . , . B.t.w. , , , , .

. , one.

+3

. , - , , , , , , / ,

, POCO, , . , , , , IPropertyChanged, .

, , , IValidator, , .

public interface IValidator
{
   IList<RuleViolation> GetViolations();
}

NHibernate Validation ( nhibernate ORM, . .

//I can't remember the exact syntax but it is very similar to this
public class MyEntity
{

[NHibernateValidation(Length(min=1, max=10)]
public String Name {get;set;}

}

//... and then later ...
NHibernateValidator.Validate(myEntity);

: , , , NHibernate Validation

+2

-, @i8abug.

, . , , , , .

, .

.

. , , . , . , , , . , , , , , .

, . . , 2 . ..: . ? . , .

, , "" , , , .. .

, . , , , . . , , . . , , . , , Inversion of Control ; ; , .

, , , , . "" - .

+2
source

Source: https://habr.com/ru/post/1780345/


All Articles