Merge pull request #1407 from chrisvire/bug-24587
[mono.git] / mcs / class / System.Design / System.Windows.Forms.Design / DocumentDesigner.cs
index f6b5025233d65b88458bddf76c9ec7760b161abe..14e6aa682d3be1159abc6809278fe2584da7f889 100644 (file)
@@ -289,15 +289,14 @@ namespace System.Windows.Forms.Design
 
                private void InitializeSelectionService ()
                {
-                       IServiceContainer serviceContainer = this.GetService (typeof (IServiceContainer)) as IServiceContainer;
-                       if (serviceContainer.GetService (typeof (ISelectionService)) != null)
-                               serviceContainer.RemoveService (typeof (ISelectionService));
-
-                       UISelectionService selection = new UISelectionService (serviceContainer);
-                       serviceContainer.AddService (typeof (ISelectionService), (ISelectionService) selection);
-                       serviceContainer.AddService (typeof (IUISelectionService), (IUISelectionService) selection);
+                       IUISelectionService guiSelectionService = this.GetService (typeof (IUISelectionService)) as IUISelectionService;
+                       if (guiSelectionService == null) {
+                               IServiceContainer serviceContainer = this.GetService (typeof (IServiceContainer)) as IServiceContainer;
+                               serviceContainer.AddService (typeof (IUISelectionService), (IUISelectionService) new UISelectionService (serviceContainer));
+                       }
 
-                       selection.SetSelectedComponents (new IComponent[] { this.Component });
+                       ISelectionService selectionService = this.GetService (typeof (ISelectionService)) as ISelectionService;
+                       selectionService.SetSelectedComponents (new IComponent[] { this.Component });
                }
 
 #if !NET_2_0