1

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.

Omu
  • 69,856
  • 92
  • 277
  • 407
reggieboyYEAH
  • 870
  • 3
  • 11
  • 28

1 Answers1

1

There's a sample project on codeplex that uses ValueInjecter to map Entities to ViewModels and back: http://prodinner.codeplex.com/

In general as long as it works it's ok, and if it isn't you are going to refactor it afterwards, when you are going to see the bigger picture

Omu
  • 69,856
  • 92
  • 277
  • 407