Can anyone please explain how does the AfterMap function initalises the class objects passed in the lambda expression? When i run this bit of code as myself, it populates the dest object with my details. i can't figure out how is it doing that? but if someone can tell me how does it go about initialising classes, that will help me go in the right direction please.
AutoMapper.Mapper.CreateMap(Of Service.User, Models.User)() _ .ForMember(Function(dest As Models.User) dest.EmployeeNumber, Sub(opt) opt.MapFrom(Function(src As Service.User) src.IdentityNumber)) _ .AfterMap((Sub(src As Service.User, dest As Models.User) 'Extract the group names for the current application. dest.Groups = New List(Of String) Using service = ApplicationSecurityManager.Service.Factory.GetService() Dim applicationPermissions = service.LoadPermissionsForUser(dest.Username, MyBase.EnvironmentCode) If (Not applicationPermissions Is Nothing AndAlso applicationPermissions.Any(Function(x) x.Code = MyBase.ApplicationCode)) Then dest.Groups = applicationPermissions.Single(Function(x) x.Code = MyBase.ApplicationCode).GroupNames.ToList() End If End Using End Sub))
-------Edited with Answer----
The objects have values in them because they are called after Mapping.Map function is called and that's where actual object with values is passed and then AfterMap function is called and that's how it has the values in it.