diff --git a/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs b/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs index 7ce487372d..b9396e5e40 100644 --- a/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs +++ b/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs @@ -59,7 +59,7 @@ public IEnumerable RegisterComponents(Container container) registrator.register_instance(() => fileSystem); registrator.register_instance(() => Config.get_configuration_settings()); mainRegistrator.register_dependencies(registrator, configuration); - //registrator.register_assembly_commands(Assembly.GetExecutingAssembly()); + registrator.register_assembly_commands(Assembly.GetExecutingAssembly()); registrator.CanReplaceRegister = false; var assemblies = fileSystem.get_extension_assemblies(); @@ -151,11 +151,11 @@ You can override this compatibility check and force loading the extension by pas hasRegisteredDependencies = !clonedRegistrator.RegistrationFailed; } - //if (hasRegisteredDependencies) - //{ - // clonedRegistrator.register_assembly_commands(assembly); - // hasRegisteredDependencies = !clonedRegistrator.RegistrationFailed; - //} + if (hasRegisteredDependencies) + { + clonedRegistrator.register_assembly_commands(assembly); + hasRegisteredDependencies = !clonedRegistrator.RegistrationFailed; + } if (hasRegisteredDependencies && !clonedRegistrator.RegistrationFailed) { diff --git a/src/chocolatey/infrastructure.app/registration/SimpleInjectorContainerRegistrator.cs b/src/chocolatey/infrastructure.app/registration/SimpleInjectorContainerRegistrator.cs index a430f73526..efd12c589b 100644 --- a/src/chocolatey/infrastructure.app/registration/SimpleInjectorContainerRegistrator.cs +++ b/src/chocolatey/infrastructure.app/registration/SimpleInjectorContainerRegistrator.cs @@ -80,6 +80,31 @@ public object Clone() return cloned; } + public void register_assembly_commands(IAssembly assembly) + { + try + { + var types = assembly.get_loadable_types() + .Where(t => t.IsClass && !t.IsAbstract && typeof(ICommand).IsAssignableFrom(t) && t.GetCustomAttribute() != null); + + foreach (var t in types) + { + if (RegistrationFailed) + { + break; + } + + register_command(t); + } + } + catch (Exception ex) + { + this.Log().Warn("Unable to register commands for '{0}'. Continuing without registering commands!", assembly.GetName().Name); + this.Log().Warn(ex.Message); + RegistrationFailed = true; + } + } + public void register_command(Type commandType) { ensure_not_built();