First, let's look at the following picture, which explains the concept of .Net RIA Service .

(source: nikhilk.net )
As you can see, the application has application logic (business rule), which can be implemented both on the server side (databases + repositories + external services) and on the client side (asp.net + Silverlight + WCF web page)
Then I create some data class that contains some validation rule.
namespace [SolutionName].Models { public interface IUser { Guid ID { get; set; } [Required] [StringLength(15)] [RegularExpression("^[a-zA-Z][a-zA-Z_]+$")] string LoginName { get; set; } [Required] [StringLength(255)] string HashedPassword { get; set; } DateTime CreateTime { get; set; } [StringLength(255)] string Description { get; set; } [Required] Role Role { get; set; } } }
After that, I create some custom Model Binder to validate the data when users publish it to the controllers. Thus, I can make sure that each Model is valid before saving it.
public ActionResult SaveData() { if(ModelState.IsValid) { // logic for saving data } else { // logic for displaying error message } }
However, some view pages do not require all the fields in the data type. You need several fields in the data type. I cannot split this data type into multiple interfaces, depending on which data field the browse page requires. Because some data fields are duplicated. Moreover, it will also separate the application logic.
for example
- The LogOn view uses only 2 fields, including LogOnName and HashedPassword.
- The ChangePassword view uses only 2 fields, including Id and HashedPassword.
- The UserProfile view uses 4 fields, including ID, LogOnName, HashedPassword, and Description.
Do you have any ideas for solving this problem? I think this is very similar to the concept of AOP.
By the way, I can solve this problem by adding a list box that contains unused fields. But this idea is pretty bad when I use it with a large data type that contains more than 100 fields.
namespace [SolutionName].Models { public interface IUser {
Thanks,
oop asp.net-mvc
Soul_master
source share