Great tool, thanks so much for your work. I'm using ValueInjecter in an ASP.NET MVC4 site to do all sorts of mapping, and have run into an odd situation. I have a nested domain object that I've written a ConventionInjection for, and have also
overridden UnflatLoopValueInjectionM<string, string> to
convert null values to string.Empty. Now, when I inject my view model back to my nested domain object, the injection appears to be missing everything on the top-level domain object that isn't a string. The domain object is "Client,"
which has a nested type "Person." Here are my injection overrides:
public class NullStringUnflatLoopValueInjection : UnflatLoopValueInjection<string, string>
protected override string SetValue(string sourceValue)
return sourceValue ?? string.Empty;
public class ClientViewModelToPerson : ConventionInjection
protected override bool Match(ConventionInfo c)
return c.SourceProp.Name == "FirstName" && c.SourceProp.Type == typeof (string) &&
c.TargetProp.Name == "Person" && c.TargetProp.Type == typeof (Data.Person);
protected override object SetValue(ConventionInfo c)
var source = c.Source.Value as ViewModels.Client.ClientViewModel;
if (source == null)
var dest = c.TargetProp.Value as Data.Person;
if (dest == null)
dest.FirstName = source.FirstName ?? string.Empty;
dest.MiddleName = source.MiddleName ?? string.Empty;
dest.LastName = source.LastName ?? string.Empty;
dest.NickName = source.NickName ?? string.Empty;
dest.IsFemale = source.IsFemale;
dest.DateOfBirth = source.DateOfBirth;
dest.Ssn = source.Ssn ?? string.Empty;
dest.Phone1 = source.Phone1 ?? string.Empty;
dest.Phone2 = source.Phone2 ?? string.Empty;
dest.Phone3 = source.Phone3 ?? string.Empty;
I've validated that the ClientViewModelToPerson injector is working correctly, but have found that the additional properties on the root Client object that
are not strings do not get mapped. Here's my controller code.
public ActionResult Edit(ClientViewModel clientViewModel)
var client = _clientRepo.GetClient(viewModel.ClientId);
So my question is, do I have to override for all types or specify the Client object mappings in one of the injections? Am I missing an injection in my controller? I cannot add a default InjectFrom, as my model does not allow nulls on one of the
Client string properties. Hence the NullStringUnflatLoopValueInjection override.
Thanks very much for your help.