I've started using Autofac
and want to scan some DLL's and get Autofac
to register some of the classes within them.
The classes that I'm interested in all inherit from a PluginBase class but the below code doesn't seem to be registering them. Can anyone help?
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(assemblies)
.Where(t => t.BaseType == typeof(PluginBase))
.AsImplementedInterfaces()
.AsSelf();
var container = builder.Build();
var pluginClasses = container.Resolve<IEnumerable<PluginBase>>();
//pluginClasses is empty!!!!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…