public static void AddProfilesForAttributes(this MapperConfigurationExpression cfg, IEnumerable <Assembly> assembliesToScan, AddedMapContext mapContext, IFactory factory) { var allTypes = assembliesToScan.Where(a => !a.IsDynamic && a != typeof(NamedProfile).Assembly).SelectMany(a => a.DefinedTypes).ToArray(); var autoMapAttributeProfile = new NamedProfile(nameof(YuzuMapAttribute)); var config = factory.GetInstance <IYuzuConfiguration>(); var importConfig = factory.GetInstance <IYuzuDeliveryImportConfiguration>(); foreach (var viewModels in allTypes) { foreach (var attribute in viewModels.GetCustomAttributes <YuzuMapAttribute>()) { var cmsModel = config.CMSModels.Where(x => x.Name == attribute.SourceTypeName).FirstOrDefault(); if (cmsModel != null && !mapContext.Has(cmsModel, viewModels) && !importConfig.IgnoreUmbracoModelsForAutomap.Contains(cmsModel.Name)) { cfg.CreateMap(cmsModel, viewModels); } } } }