Skip to content

Commit 74e527e

Browse files
committed
Reinstate Command Registration code
1 parent bedae7f commit 74e527e

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

Rubberduck.Main/Root/RubberduckIoCInstaller.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,6 @@ private void RegisterFactories(IWindsorContainer container, Assembly[] assemblie
228228

229229
private static void RegisterSpecialFactories(IWindsorContainer container)
230230
{
231-
//container.Register(Component.For<IDeclarationFinderFactory>()
232-
// .ImplementedBy<DeclarationFinderFactory>()
233-
// .LifestyleSingleton());
234231
container.Register(Component.For<IFolderBrowserFactory>()
235232
.ImplementedBy<DialogFactory>()
236233
.LifestyleSingleton());
@@ -558,19 +555,19 @@ private void RegisterCommands(IWindsorContainer container)
558555
//note: convention: the registration name for commands is the type name, not the full type name.
559556
//Otherwise, namespaces would get in the way when binding to the menu items.
560557
RegisterCommandsWithPresenters(container);
561-
562-
//var commandsForCommandMenuItems = Assembly.GetExecutingAssembly().GetTypes()
563-
// .Where(type => type.IsClass && typeof(ICommandMenuItem).IsAssignableFrom(type))
564-
// .Select(type => CommandNameFromCommandMenuName(type.Name))
565-
// .ToHashSet();
558+
559+
// assumption: All Commands (and CommandMenuItems by extension) are in the same assembly as CommandBase
560+
var commandsForCommandMenuItems = Assembly.GetAssembly(typeof(CommandBase)).GetTypes()
561+
.Where(type => type.IsClass && typeof(ICommandMenuItem).IsAssignableFrom(type))
562+
.Select(type => CommandNameFromCommandMenuName(type.Name))
563+
.ToHashSet();
566564

567565
container.Register(Classes.FromAssemblyContaining<CommandBase>()
568566
.Where(type => type.Namespace != null
569567
&& type.Namespace.StartsWith(typeof(CommandBase).Namespace ?? string.Empty)
570568
&& (type.BaseType == typeof(CommandBase) || type.BaseType == typeof(RefactorCommandBase))
571569
&& type.Name.EndsWith("Command")
572-
// FIXME something something commandsForCommandMenuItems ...
573-
&& type.Assembly.GetTypes().Any(menuItemType => menuItemType.Name == (type.Name + "MenuItem")))
570+
&& commandsForCommandMenuItems.Contains(type.Name))
574571
.WithService.Self()
575572
.WithService.Select(new[] { typeof(CommandBase) })
576573
.LifestyleTransient()

0 commit comments

Comments
 (0)