Skip to content

Commit 72f1fe6

Browse files
committed
Update DockablePresenter injection mechanism
This change also motivates #4379
1 parent 8df46dd commit 72f1fe6

File tree

7 files changed

+22
-67
lines changed

7 files changed

+22
-67
lines changed

Rubberduck.Core/UI/Command/CodeExplorerCommand.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Runtime.InteropServices;
22
using NLog;
3+
using Rubberduck.UI.CodeExplorer;
34

45
namespace Rubberduck.UI.Command
56
{
@@ -9,9 +10,9 @@ namespace Rubberduck.UI.Command
910
[ComVisible(false)]
1011
public class CodeExplorerCommand : CommandBase
1112
{
12-
private readonly IDockablePresenter _presenter;
13+
private readonly CodeExplorerDockablePresenter _presenter;
1314

14-
public CodeExplorerCommand(IDockablePresenter presenter)
15+
public CodeExplorerCommand(CodeExplorerDockablePresenter presenter)
1516
: base(LogManager.GetCurrentClassLogger())
1617
{
1718
_presenter = presenter;

Rubberduck.Core/UI/Command/CodeMetricsCommand.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using NLog;
2+
using Rubberduck.UI.CodeMetrics;
23
using System.Runtime.InteropServices;
34

45
namespace Rubberduck.UI.Command
56
{
67
[ComVisible(false)]
78
public class CodeMetricsCommand : CommandBase
89
{
9-
private readonly IDockablePresenter _presenter;
10+
private readonly CodeMetricsDockablePresenter _presenter;
1011

11-
public CodeMetricsCommand(IDockablePresenter presenter)
12+
public CodeMetricsCommand(CodeMetricsDockablePresenter presenter)
1213
: base(LogManager.GetCurrentClassLogger())
1314
{
1415
_presenter = presenter;

Rubberduck.Core/UI/Command/InspectionResultsCommand.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Runtime.InteropServices;
22
using NLog;
3+
using Rubberduck.UI.Inspections;
34

45
namespace Rubberduck.UI.Command
56
{
@@ -9,9 +10,9 @@ namespace Rubberduck.UI.Command
910
[ComVisible(false)]
1011
public class InspectionResultsCommand : CommandBase
1112
{
12-
private readonly IDockablePresenter _presenter;
13+
private readonly InspectionResultsDockablePresenter _presenter;
1314

14-
public InspectionResultsCommand(IDockablePresenter presenter)
15+
public InspectionResultsCommand(InspectionResultsDockablePresenter presenter)
1516
: base(LogManager.GetCurrentClassLogger())
1617
{
1718
_presenter = presenter;

Rubberduck.Core/UI/Command/MenuItems/TestExplorerCommandMenuItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rubberduck.UI.Command.MenuItems
44
{
5-
public class TestExplorerCommandMenuItem : CommandMenuItemBase
5+
internal class TestExplorerCommandMenuItem : CommandMenuItemBase
66
{
77
public TestExplorerCommandMenuItem(TestExplorerCommand command)
88
: base(command)

Rubberduck.Core/UI/Command/TestExplorerCommand.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using System.Runtime.InteropServices;
22
using NLog;
3+
using Rubberduck.UI.UnitTesting;
34

45
namespace Rubberduck.UI.Command
56
{
67
[ComVisible(false)]
7-
public class TestExplorerCommand : CommandBase
8+
internal class TestExplorerCommand : CommandBase
89
{
9-
private readonly IDockablePresenter _presenter;
10+
private readonly TestExplorerDockablePresenter _presenter;
1011

11-
public TestExplorerCommand(IDockablePresenter presenter)
12+
public TestExplorerCommand(TestExplorerDockablePresenter presenter)
1213
: base(LogManager.GetCurrentClassLogger())
1314
{
1415
_presenter = presenter;

Rubberduck.Core/UI/Command/ToDoExplorerCommand.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Runtime.InteropServices;
22
using NLog;
3+
using Rubberduck.UI.ToDoItems;
34

45
namespace Rubberduck.UI.Command
56
{
@@ -9,9 +10,9 @@ namespace Rubberduck.UI.Command
910
[ComVisible(false)]
1011
public class ToDoExplorerCommand : CommandBase
1112
{
12-
private readonly IDockablePresenter _presenter;
13+
private readonly ToDoExplorerDockablePresenter _presenter;
1314

14-
public ToDoExplorerCommand(IDockablePresenter presenter)
15+
public ToDoExplorerCommand(ToDoExplorerDockablePresenter presenter)
1516
: base(LogManager.GetCurrentClassLogger())
1617
{
1718
_presenter = presenter;

Rubberduck.Main/Root/RubberduckIoCInstaller.cs

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,6 @@ private void RegisterCommandMenuItems(IWindsorContainer container)
620620

621621
private void RegisterCommands(IWindsorContainer container)
622622
{
623-
//note: convention: the registration name for commands is the type name, not the full type name.
624-
//Otherwise, namespaces would get in the way when binding to the menu items.
625-
RegisterCommandsWithPresenters(container);
626-
627623
// assumption: All Commands are in the same assembly as CommandBase
628624
container.Register(Classes.FromAssemblyContaining(typeof(CommandBase))
629625
.IncludeNonPublicTypes()
@@ -636,46 +632,6 @@ private void RegisterCommands(IWindsorContainer container)
636632
.LifestyleTransient());
637633
}
638634

639-
private void RegisterCommandsWithPresenters(IWindsorContainer container)
640-
{
641-
// FIXME these registrations shouldn't be IoC's business. the presenters should require those themselves!
642-
// Possible solution: Property Injection
643-
container.Register(Component.For<CommandBase>()
644-
.ImplementedBy<RunAllTestsCommand>()
645-
.DependsOn(Dependency.OnComponent<IDockablePresenter, TestExplorerDockablePresenter>())
646-
.LifestyleTransient()
647-
.Named(typeof(RunAllTestsCommand).Name));
648-
container.Register(Component.For<CommandBase>()
649-
.ImplementedBy<TestExplorerCommand>()
650-
.DependsOn(Dependency.OnComponent<IDockablePresenter, TestExplorerDockablePresenter>())
651-
.LifestyleTransient()
652-
.Named(typeof(TestExplorerCommand).Name));
653-
654-
container.Register(Component.For<CommandBase>()
655-
.ImplementedBy<InspectionResultsCommand>()
656-
.DependsOn(Dependency.OnComponent<IDockablePresenter, InspectionResultsDockablePresenter>())
657-
.LifestyleTransient()
658-
.Named(typeof(InspectionResultsCommand).Name));
659-
660-
container.Register(Component.For<CommandBase>()
661-
.ImplementedBy<CodeExplorerCommand>()
662-
.DependsOn(Dependency.OnComponent<IDockablePresenter, CodeExplorerDockablePresenter>())
663-
.LifestyleTransient()
664-
.Named(typeof(CodeExplorerCommand).Name));
665-
666-
container.Register(Component.For<CommandBase>()
667-
.ImplementedBy<CodeMetricsCommand>()
668-
.DependsOn(Dependency.OnComponent<IDockablePresenter, CodeMetricsDockablePresenter>())
669-
.LifestyleSingleton()
670-
.Named(typeof(CodeMetricsCommand).Name));
671-
672-
container.Register(Component.For<CommandBase>()
673-
.ImplementedBy<ToDoExplorerCommand>()
674-
.DependsOn(Dependency.OnComponent<IDockablePresenter, ToDoExplorerDockablePresenter>())
675-
.LifestyleTransient()
676-
.Named(typeof(ToDoExplorerCommand).Name));
677-
}
678-
679635
private void RegisterSmartIndenter(IWindsorContainer container)
680636
{
681637
container.Register(Component.For<IIndenter, Indenter>()
@@ -710,17 +666,11 @@ private void RegisterDockableUserControls(IWindsorContainer container)
710666

711667
private void RegisterDockablePresenters(IWindsorContainer container)
712668
{
713-
container.Register(Component.For<IDockablePresenter>()
714-
.ImplementedBy<TestExplorerDockablePresenter>()
715-
.LifestyleSingleton());
716-
container.Register(Component.For<IDockablePresenter>()
717-
.ImplementedBy<InspectionResultsDockablePresenter>()
718-
.LifestyleSingleton());
719-
container.Register(Component.For<IDockablePresenter>()
720-
.ImplementedBy<CodeExplorerDockablePresenter>()
721-
.LifestyleSingleton());
722-
container.Register(Component.For<IDockablePresenter>()
723-
.ImplementedBy<ToDoExplorerDockablePresenter>()
669+
container.Register(Classes.FromAssemblyContaining<IDockablePresenter>()
670+
.IncludeNonPublicTypes()
671+
.BasedOn<IDockablePresenter>()
672+
.WithServiceSelf()
673+
.WithServices(new[] { typeof(IDockablePresenter) })
724674
.LifestyleSingleton());
725675
}
726676

0 commit comments

Comments
 (0)