Domain Driven Design Step 2

I want to mention SharpArhitecture project. This represents a solid architectural foundation for rapidly building maintainable web applications leveraging the ASP.NET MVC framework with NHibernate.

What I want here is to show some advantages/disadvantages and the points of interested that I faced up. So when analysing the possibilities that this code offers, I discovered that :

1) NHibernate validation is not suitable for a series of scenarious that mostly enterprise level applications require. Let's assume that we have the following scenario: there is the entity 'case' and this entity should be introduced (inserted) in our system by the worker with position 'Secretary'. The Secretary shoul introduce only the CaseName. Later the worker that is in position 'President' should alter the case and set the number.

public class Case
{
  public virtual int Id  { get { return id; }  }

  [NotEmpty, NotNull]
  public virtual string CaseName  {  get ; set ;  }

  [Email]
  public virtual string Email {  get ; set ;  }

  [Min(20000, Message="The number should be greater than 20000!")]
  public int Nr{  get ; set ;  }
  
  ///...
}

In the scenario described above we better have also 2 validation scenarious. It's a simple case, but assume that when creating the record the number should be greater than 20000 and when updating the record the Number should be less 2000. Of course non-sense here, but assume it's a custom scenario. Than in this case the NHibernate validators are not suitable for accomplishing the validation.

I solved this issue by eliminationg the Nhibernate validators and pass to FluentValidation framework. Now I have different validator classes for different scenaious. It's more flexible approach and gives the power of more deep validation.

The advantage is considerable we don't tie the validation to the entity. We have in my case:

public class Case
{
  public virtual int Id  { get { return id; }  }

  public virtual string CaseName  {  get ; set ;  }

  public virtual string Email {  get ; set ;  }

  public int Nr{  get ; set ;  }
  
  ///...
}

and some classes for validation with structure similar to:

public class CaseValidator:AbstractValidator<Case>

{

public CaseValidator(){}

RuleFor(x=>x.CaseName).NotEmpty();

RuleFor(x=>x.CaseName).NotNull();

//..

}

that have different set of rules for validation that meets my custom scenarious.

Print | posted @ Sunday, March 08, 2009 8:56 PM

Comments on this entry:

No comments posted yet.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: