Which in turn leads to being able to refactor the initial code:
var type = typeof(IUnmapped);
builder
.RegisterAssemblyTypes(targetAssembly)
.Where(x => !type.IsAssignableFrom(x))
.As(type =>
type.GetInterfaces()
.Where(interfacetype =>
interfacetype.IsAssignableFrom(typeof(ICommandHandler<>))
|| interfacetype.IsAssignableFrom(typeof(IEventHandler<>))))
.AsSelf()
.InstancePerDependency();
var type = typeof(IMapped);
var skippedTypes = AppDomain.CurrentDomain
.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => !type.IsAssignableFrom(p));
Or when refactoring the old code:
var type = typeof(IMapped);
builder
.RegisterAssemblyTypes(targetAssembly)
.Where(x => type.IsAssignableFrom(x))
.As(type =>
type.GetInterfaces()
.Where(interfacetype =>
interfacetype.IsAssignableFrom(typeof(ICommandHandler<>))
|| interfacetype.IsAssignableFrom(typeof(IEventHandler<>))))
.AsSelf()
.InstancePerDependency();
var skippedTypes = AppDomain.CurrentDomain
.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => !p.GetConstructors().Length == 0Any());