public static void AddMaps(IConfigFactory <IGlassMap> mapsConfigFactory) { var factory = new SitecoreSettingsFactory(); //Load referenced assemblies var assemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies().Select(Assembly.Load).ToList(); //load possible standalone assemblies assemblies.AddRange(AppDomain.CurrentDomain.GetAssemblies() .Where(assembly => assembly.GetCustomAttributes(typeof(IgnitionAutomapAttribute)).Any()) .Where(a => !assemblies.Contains(a)) .Select(a => Assembly.Load(a.FullName))); var manyTypes = assemblies.SelectMany(s => s.GetTypes()); var filteredTypes = manyTypes.Where(p => typeof(IGlassMap).IsAssignableFrom(p) && !p.IsAbstract && !p.IsInterface) .ToList(); filteredTypes.ForEach(a => mapsConfigFactory.Add(() => { var mapper = (IGlassMap)Activator.CreateInstance(a); var setting = mapper as IGlassSettingsConsumer; if (setting != null) { setting.SettingsFactory = factory; } return((IGlassMap)setting ?? mapper); })); }
public override void Process(AddMapsPipelineArgs args) { var factory = new SitecoreSettingsFactory(); var automappedAssemblies = IgnitionAutomapHelper.GetAutomappedAssemblies(); var manyTypes = automappedAssemblies.SelectMany(s => s.GetTypes()); var filteredTypes = manyTypes.Where(p => typeof(IGlassMap).IsAssignableFrom(p) && !p.IsAbstract && !p.IsInterface).ToList(); filteredTypes.ForEach(a => args.MapsConfigFactory.Add(() => { var mapper = (IGlassMap)Activator.CreateInstance(a); var setting = mapper as IGlassSettingsConsumer; if (setting != null) { setting.SettingsFactory = factory; } return((IGlassMap)setting ?? mapper); })); }