I am registering my components/services as shown here and I am also implementing a class as shown below. When I call Reload, its saying its not registered and I know it is. Any ideas?
public interface ITypeReloader
{
PluginBase Reload(Type type);
}
public class TypeReloader
{
IComponentContext _container;
public TypeReloader(IComponentContext container)
{
_container = container;
}
public PluginBase Reload(Type type)
{
(PluginBase)_container.Resolve(type); //Not registered error
}
}
The answer you link to uses
AppDomain.CurrentDomain.GetAssemblies()to get the currently loaded assemblies, and then registers any types derived fromPluginBasein them.However, assemblies are only loaded into an AppDomain when first needed. I bet the types you are interested in reside in assemblies which have not yet been loaded when you do the registration. You can check this by looking the result of
AppDomain.CurrentDomain.GetAssemblies(): is it missing any assemblies you were expecting to be there?The easiest way to fix this is by using the AutoFac MEF integration and MEF’s DirectoryCatalog instead. The DirectoryCatalog is designed exactly for this scenario.
edit: on a second look, the problem is that you register as
PluginBasebut then try to resolve as some subtype. For what you are trying to achieve here, you probably need to register.AsSelf()instead of.As<PluginBase>().