In my experience with various web service applications, a common scenario has emerged:
- Initially, a Domain Model is created (using C#). This model serves as the core of the application, housing business logic and validation rules to determine entity validity.
- Next, a "web service" layer is implemented (utilizing C#/WCF). This layer defines DTO-like objects that are exposed by the web services. These DTO-like objects are constructed from segments of domain entities in a generally high-level manner.
- Validation rules on the client-side (using JavaScript & HTML) are often duplicated in a separate format, typically through some form of JavaScript-based validation.
The challenge arises in exposing the validation rules attached to the domain entities on the client side via web services. The goal is to define these validation rules once within the domain model and have them accessible to consumer clients in various parts of the system.
The solution I've proposed thus far involves making the domain's validation rules available in a metadata format such as XML or JSON. However, a major obstacle is presented as the schema differences between the service layer's DTOs and the domain entities prevent direct transmission of the domain's validation rules to the web client - which operates under a distinct schema and structure than the domain model.
Thus, my inquiry stands: What approach can minimize manual and duplicate code while facilitating effective mapping between different schemas and layers in the application, enabling seamless interpretation of the validation rules?