im kinda new to value injecter, to the whole object to object mapping world actualy. seems like valueinjecter is one of the better choice out as of the moment. Im wondering what is the best way of mapping this kind of objects
Basically what i want is map value from a viewmodel
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; }
}
to my domain entity
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); }
}
}
i tried this code and it works but not sure if its the best way to do it
var newuserinfo = new UserInfo();
newuserinfo.InjectFrom(model);
newuserinfo.PersonName.InjectFrom(model);
And where does object-to-object mapping framework like valueinjecter fit in the system architecture? Im thinking of writing a unit tests for my object mapping.