Skip to content

Commit 4e418f7

Browse files
committed
Fix up the registrations for the generic dialogs
1 parent a4ff0ec commit 4e418f7

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

Rubberduck.Main/Root/RubberduckIoCInstaller.cs

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ public void Install(IWindsorContainer container, IConfigurationStore store)
129129
.LifestyleSingleton());
130130
container.Register(Component.For<SearchResultPresenterInstanceManager>()
131131
.LifestyleSingleton());
132-
132+
133+
RefactoringDialogRefactor(container);
133134
RegisterDockablePresenters(container);
134135
RegisterDockableUserControls(container);
135136

@@ -602,6 +603,76 @@ private Type[] ToolsMenuItems()
602603
return items.ToArray();
603604
}
604605

606+
private void RefactoringDialogRefactor(IWindsorContainer container)
607+
{
608+
container.Register(Types
609+
.FromAssemblyInThisApplication()
610+
.IncludeNonPublicTypes()
611+
.BasedOn(typeof(IRefactoringView<>))
612+
.LifestyleTransient()
613+
.WithServiceSelect((type, types) =>
614+
{
615+
var face = type.GetInterfaces().FirstOrDefault(i =>
616+
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRefactoringView<>));
617+
618+
return face == null ? new[] { type } : new[] { type, face };
619+
})
620+
);
621+
container.Register(Types
622+
.FromAssemblyInThisApplication()
623+
.IncludeNonPublicTypes()
624+
.BasedOn(typeof(IRefactoringViewModel<>))
625+
.LifestyleSingleton()
626+
.WithServiceSelect((type, types) =>
627+
{
628+
var face = type.GetInterfaces().FirstOrDefault(i =>
629+
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRefactoringViewModel<>));
630+
631+
return face == null ? new[] { type } : new[] {type, face};
632+
})
633+
);
634+
container.Register(Types
635+
.FromAssemblyInThisApplication()
636+
.IncludeNonPublicTypes()
637+
.BasedOn(typeof(IRefactoringDialog<,,>))
638+
.LifestyleTransient()
639+
.WithServiceSelect((type, types) =>
640+
{
641+
var face = type.GetInterfaces().FirstOrDefault(i =>
642+
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRefactoringDialog<,,>));
643+
644+
if (face == null)
645+
{
646+
return new[] { type };
647+
}
648+
649+
var model = face.GenericTypeArguments[0];
650+
651+
var view = face.GenericTypeArguments[1];
652+
var interfaceView = view.GetInterfaces().FirstOrDefault(i =>
653+
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRefactoringView<>));
654+
655+
if (interfaceView == null)
656+
{
657+
return new[] { type };
658+
}
659+
660+
var viewModel = face.GenericTypeArguments[2];
661+
var interfaceViewModel = viewModel.GetInterfaces().FirstOrDefault(i =>
662+
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRefactoringViewModel<>));
663+
664+
if (interfaceViewModel == null)
665+
{
666+
return new[] {type};
667+
}
668+
669+
var closedFace = typeof(IRefactoringDialog<,,>).MakeGenericType(model, interfaceView, interfaceViewModel);
670+
671+
return new[] { type, closedFace };
672+
})
673+
);
674+
}
675+
605676
private void RegisterCommandMenuItems(IWindsorContainer container)
606677
{
607678
//note: The name of a registration is the full name of the implementation if not specified otherwise.

RubberduckTests/Refactoring/MockIoC/MockRefactoringContainer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ public void Install(IWindsorContainer container, IConfigurationStore store)
8585
.LifestyleSingleton()
8686
);
8787

88+
/*
8889
container.Register(Component
8990
.For(typeof(IRefactoringView<>))
9091
.ImplementedBy(typeof(RefactoringViewStub<>))
9192
.LifestyleSingleton()
9293
);
94+
*/
9395

9496
container.Register(Component
9597
.For(typeof(RenameViewModel), typeof(IRefactoringViewModel<RenameModel>))

0 commit comments

Comments
 (0)