Dogfooding with Lightweight Object2Object Mapper

After gettting some feedback about my Object 2 Object Mapper on codeproject I made some amendments over the weekend and wanted to put them into practice, thats when I decided to go down the dogfooding route with the Staff Intranet project being my dog so to speak.

Mapping in the Staff Intranet was handled by having a Mapper object for each mapper permutation each deriving from an IMapper generic interface. So I began by making sure all my tests ran ok then one by one replacing each bit of code that referenced the mappers and instead setup the mappings using a SimpleObjectMapper and registered it into the SimpleObjectMapperContainer, i could then replace the code using the existing mapper to use the registered SimpleObjectMapper, re-run the tests to make sure everything was still expected.

There were a few little areas that needed to be looked at but I was very pleased with the result of making the switch, in the end using the SimpleObjectMapper made the following objects redundant:

And was replaced by the following which is ran inside the Application_Start method:

SimpleObjectMapperContainer.RegisterMapper(new SimpleObjectMapper());
SimpleObjectMapperContainer.RegisterMapper(new SimpleObjectMapper());

SimpleObjectMapperContainer.RegisterMapper(new SimpleObjectMapper()
                                            .Explicit((staff, staffDTO) => staffDTO.LocationId = staff.Location.Id)
                                            .Explicit((staff, staffDTO) => staffDTO.LocationDescription = staff.Location.Value)
                                            .Explicit((staff, staffDTO) => staffDTO.Photo.Data = staff.Photo));

SimpleObjectMapperContainer.RegisterMapper(new SimpleObjectMapper()
                                            .Explicit((staffDTO, staff) =>
                                                if ((staffDTO.Photo.SaveOption == PhotoSaveOption.Update) && (staffDTO.Photo.Data != null))
                                                    staff.Photo = staffDTO.Photo.Data;
                                            .Explicit((staffDTO, staff) => staff.Location.Id = staffDTO.LocationId));

SimpleObjectMapperContainer.RegisterMapper(new SimpleObjectMapper()
                                            .Explicit((domain, dto) =>
                                                foreach (var item in domain.Results)
                                                    dto.AddError(item.ValidationId, item.Message);

With me being on holiday I hope to get the codeproject article updated in the next few days.