1

I have this simple code:

using Omu.ValueInjecter;

namespace InjectionTest
{
    public class Partner
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public City City { get; set; }
    }

    public class City
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    public class PartnerViewModel
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string CityName { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var city = new City()
            {
                Id = 1,
                Name = "Athens"
            };

            var partner = new Partner()
            {
                Id = 1,
                Name = "Acme d.o.o.",
                City = city
            };

            var vm = new PartnerViewModel();

            vm.InjectFrom(partner);

        }
    }
}

As I understand Valueinjector maps complex object graphs by class name + property name. I expected the vm object property CityName to be "Athens" after the injection, but it is null. I guess I am missing something. Help appreciated.

zszep
  • 4,450
  • 4
  • 38
  • 58
  • Please read my answer hope it would help to resolve your problem:[ValueInjector Value Mapping](https://stackoverflow.com/a/59598037/8225165) – Rahul Dhoundiyal Jan 05 '20 at 08:09

1 Answers1

2

Never mind. After going through the samples I realized that the line

vm.InjectFrom(partner);

should read

vm.InjectFrom<FlatLoopInjection>(partner);

I was under the impression that this should be the default, but seems not.

zszep
  • 4,450
  • 4
  • 38
  • 58