我对值注入器有点陌生,实际上是整个对象到对象的映射世界。似乎 valueinjecter 是目前更好的选择之一。我想知道映射这种对象的最佳方法是什么
基本上我想要的是来自视图模型的地图值
public class RegisterModel
{
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email address")]
public string Email { get; set; }
[Required]
[ValidatePasswordLength]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
[Required]
[StringLength(255)]
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Display(Name = "Middle Name")]
public string MiddleName { get; set; }
[Required]
[StringLength(255)]
[Display(Name = "Last Name")]
public string LastName { get; set; }
}
到我的域实体
public class UserInfo : EntityBase
{
public UserInfo()
{
PersonName = new PersonName();
}
public virtual string Email { get; set; }
public virtual string Password { get; set; }
public virtual PersonName PersonName { get; set; }
}
public class PersonName
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string Fullname1
{
get { return string.Format(@"{0}, {1} {2}", LastName, FirstName, MiddleName); }
}
public string Fullname2
{
get { return string.Format(@"{0} {1} {2}", FirstName, MiddleName, LastName); }
}
}
我试过这段代码,它可以工作,但不确定它是否是最好的方法
var newuserinfo = new UserInfo();
newuserinfo.InjectFrom(model);
newuserinfo.PersonName.InjectFrom(model);
像 valueinjecter 这样的对象到对象映射框架在系统架构中的位置如何?我正在考虑为我的对象映射编写单元测试。