public ContinentsController(IContinentsDataService service, ICountriesDataService countriesService, ILoggerFactory loggerFactory) { this.service = service ?? throw new ArgumentNullException(nameof(service)); this.countriesService = countriesService ?? throw new ArgumentNullException(nameof(countriesService)); this.logger = loggerFactory?.CreateLogger(this.GetType()); var mapperConfiguration = new MapperConfiguration(c => { c.CreateMap <IContinent, ContinentViewModel>() .ForMember( destinationMember: d => d.Synonyms, memberOptions: o => o.ResolveUsing(x => x.Synonyms?.Select(s => new SynonymViewModel { Id = s.Id, Name = s.Name, LanguageCode = s.LanguageCode.ToString() }))) .ForMember( destinationMember: d => d.Countries, memberOptions: o => o.ResolveUsing(x => x.Countries?.Select(s => new CountryViewModel { Id = s.Id, Name = s.Name, LanguageCode = s.LanguageCode }))) .ForMember( destinationMember: d => d.NumberOfCountries, memberOptions: o => o.ResolveUsing(x => x.Countries.Count)); c.CreateMap <ContinentRequestModel, ContinentViewModel>() .ForMember( destinationMember: d => d.Synonyms, memberOptions: o => o.ResolveUsing(x => x.Synonyms?.Select(s => new SynonymViewModel { Id = s.Id, Name = s.Name, LanguageCode = s.LanguageCode.ToString() }))) .ForMember( destinationMember: d => d.Countries, memberOptions: o => o.ResolveUsing(x => x.Countries?.Select(s => new CountryViewModel { Id = s.Id, Name = s.Name, LanguageCode = s.LanguageCode }))) .ForMember( destinationMember: d => d.NumberOfCountries, memberOptions: o => o.ResolveUsing(x => x.Countries.Count)); c.CreateMap <IContinentSynonym, SynonymResponseModel>(); }); this.mapper = mapperConfiguration.CreateMapper(); }
public CountriesController(ICountriesDataService service) { this.service = service ?? throw new ArgumentNullException(nameof(service)); }