I am working on porting an ASP.NET project to RC2. I use AutoFac to try to list the classes that use the base AutoMapper Profile class to configure all of my mapping profiles without calling them explicitly. Earlier in the old version of ASP.NET (even in RC1), I was able to use the following code:
public class AutoMapperModule : Module { protected override void Load(ContainerBuilder builder) { builder.RegisterAssemblyTypes().AssignableTo(typeof(Profile)).As<Profile>(); builder.Register(context => { var profiles = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(IoC.GetLoadableTypes) .Where(t => t != typeof(Profile) && t.Name != "NamedProfile" && typeof(Profile).IsAssignableFrom(t)); var config = new MapperConfiguration(cfg => { foreach (var profile in profiles) { cfg.AddProfile((Profile)Activator.CreateInstance(profile)); } }); return config; }) .AsSelf() .As<IConfigurationProvider>() .SingleInstance(); builder.Register(c => c.Resolve<MapperConfiguration>().CreateMapper(c.Resolve)).As<IMapper>().InstancePerLifetimeScope(); builder.RegisterType<MappingEngine>().As<IMappingEngine>(); } }
This worked fantastic until I tried to convert my project to RC2 using the new netcoreapp1.0 framework, but now I get a development-time error on AppDomain, stating that "AppDomain does not exist in the current context." I saw some suggestions about using ILibraryManager or DependencyContext for this, but I cannot figure out how to make any of them work. Any suggestions?
source share