/// <summary> /// Construct using a custom, derived MapperConfigurationFactory instance and a collection of specified mapping profiles. /// </summary> /// <param name="mapperConfigurationFactory">Custom configuration factory for providing global configuration for all mappers.</param> /// <param name="profiles">Mapping profiles to configure specific type mappers.</param> public MapperFactory(MapperConfigurationFactory mapperConfigurationFactory, IEnumerable <MappingProfile> profiles) { if (mapperConfigurationFactory == null) { throw new ArgumentNullException(nameof(mapperConfigurationFactory)); } if (profiles == null) { throw new ArgumentNullException(nameof(profiles)); } this.profiles = profiles.ToList(); if (this.profiles.Count == 0) { throw new ArgumentException("Cannot instantiate MapperFactory without any mapping profiles.", nameof(profiles)); } if (this.profiles.Any(p => p == null)) { throw new ArgumentException("Cannot instantiate MapperFactory with null mapping profiles.", nameof(profiles)); } var mapperConfiguration = mapperConfigurationFactory.CreateMapperConfiguration(this.profiles); mapper = mapperConfiguration.CreateMapper(); }
/// <summary> /// Construct using a custom, derived MapperConfigurationFactory instance and specified mapping profiles. /// </summary> /// <param name="mapperConfigurationFactory">Custom configuration factory for providing global configuration for all mappers.</param> /// <param name="profile">Mapping profile to configure specific type mapper.</param> /// <param name="profiles">Mapping profiles to configure specific type mappers.</param> public MapperFactory(MapperConfigurationFactory mapperConfigurationFactory, MappingProfile profile, params MappingProfile[] profiles) : this(mapperConfigurationFactory, new[] { profile }.Concat(profiles)) { }