{"action":"created","issue":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1283","repository_url":"https://api.github.com/repos/AutoMapper/AutoMapper","labels_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1283/labels{/name}","comments_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1283/comments","events_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1283/events","html_url":"https://github.com/AutoMapper/AutoMapper/issues/1283","id":155278376,"number":1283,"title":"Mapping nested objects","user":{"login":"ben-wallis","id":11904214,"avatar_url":"https://avatars.githubusercontent.com/u/11904214?v=3","gravatar_id":"","url":"https://api.github.com/users/ben-wallis","html_url":"https://github.com/ben-wallis","followers_url":"https://api.github.com/users/ben-wallis/followers","following_url":"https://api.github.com/users/ben-wallis/following{/other_user}","gists_url":"https://api.github.com/users/ben-wallis/gists{/gist_id}","starred_url":"https://api.github.com/users/ben-wallis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ben-wallis/subscriptions","organizations_url":"https://api.github.com/users/ben-wallis/orgs","repos_url":"https://api.github.com/users/ben-wallis/repos","events_url":"https://api.github.com/users/ben-wallis/events{/privacy}","received_events_url":"https://api.github.com/users/ben-wallis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-05-17T14:45:41Z","updated_at":"2016-05-17T15:40:41Z","closed_at":null,"body":"We recently moved from the deprecated static `Mapper` class to dependency injecting `IMapper` on a project I'm currently working on and I'm wondering what the correct way to deal with mapping nested objects is. Previously we could do something like this:\r\n\r\n```\r\nCreateMap<Customer, CustomerDto>()\r\n            .ForMember(dest => dest.Address, opts => opts.MapFrom(src => Mapper.Map<AddressDto>(src.Address)))\r\n```\r\n\r\nWhich would map the `Customer` and it's child `Address` to a `CustomerDto` containing an `AddressDto`. When using a `Profile` however I'm not sure of the correct way to access the mapper to do nested mapping. I've come up with a dirty hack of setting a private property to the constructed mapper object after configuration but surely this isn't the correct way to do this. Example:\r\n\r\n```\r\n\r\nprotected void Application_Start(object sender, EventArgs e)\r\n{\r\n    // .. snip .. //\r\n    \r\n    var fooProfile = new FooProfile();\r\n    var autoMapperConfig = new MapperConfiguration(cfg => cfg.AddProfile(fooProfile));\r\n    autoMapperConfig.AssertConfigurationIsValid();\r\n\r\n    var mapper = autoMapperConfig.CreateMapper();\r\n\r\n    fooProfile.Mapper = mapper;\r\n\r\n    _container.Register(Component\r\n        .For<IMapper>()\r\n        .Instance(mapper)\r\n        .LifeStyle.Singleton);\r\n        \r\n    // .. snip .. //\r\n}\r\n    \r\npublic class FooProfile : Profile\r\n{\r\n    public IMapper Mapper { private get; set; }\r\n\r\n    protected override void Configure()\r\n    {\r\n        CreateMap<Address, AddressDto();\r\n        CreateMap<Customer, CustomerDto>()\r\n            .ForMember(dest => dest.Address, opts => opts.MapFrom(src => Mapper.Map<AddressDto>(src.Address)))\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/comments/219759095","html_url":"https://github.com/AutoMapper/AutoMapper/issues/1283#issuecomment-219759095","issue_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1283","id":219759095,"user":{"login":"TylerCarlson1","id":6801536,"avatar_url":"https://avatars.githubusercontent.com/u/6801536?v=3","gravatar_id":"","url":"https://api.github.com/users/TylerCarlson1","html_url":"https://github.com/TylerCarlson1","followers_url":"https://api.github.com/users/TylerCarlson1/followers","following_url":"https://api.github.com/users/TylerCarlson1/following{/other_user}","gists_url":"https://api.github.com/users/TylerCarlson1/gists{/gist_id}","starred_url":"https://api.github.com/users/TylerCarlson1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TylerCarlson1/subscriptions","organizations_url":"https://api.github.com/users/TylerCarlson1/orgs","repos_url":"https://api.github.com/users/TylerCarlson1/repos","events_url":"https://api.github.com/users/TylerCarlson1/events{/privacy}","received_events_url":"https://api.github.com/users/TylerCarlson1/received_events","type":"User","site_admin":false},"created_at":"2016-05-17T15:40:41Z","updated_at":"2016-05-17T15:40:41Z","body":"`.ForMember(dest => dest.DestProperty, opts => opts.MapFrom(src => src.SourceProperty));`\r\nIf you have the DestProperty type mapped to the SourceProperty type it will call the Map for you"}}