[C#] IComponentChangeService, ISelectionService & IDesignerHost

Nazgulled

Centurion
Joined
Jun 1, 2004
Messages
119
I'm doing this custom user control, I'm also working with designers and I need to use the Interfaces described in the topic subject. But I have a little situation. If any of those interfaces are not initialized somewhere in the code (ie: IComponentChangeService ICCS = (IComponentChangeService)GetService(typeof(IComponentChangeService))), I get an exception. But, I'm using these interfaces in lots of places in the code and in different classes, one of them doesn't even allow me to use the "GetService" method, it says it is not available in this context.

So, I'm looking for a way, to initialize these 3 interfaces just once and be able to use them everywhere I want. But I'm not being successful, how can I accomplish that?
 
Without seeing the code in question this isn't the easiest question to answer ;) It might be worth giving a sample piece of code that shows the problem / how you are currently dealing with the interfaces.
 
Well, that's quite hard to do as the code is pretty big and separated in classes, I don't even know where to start showing a sample...

However, someone suggested me to override the ISite interface in the User Control code and something like this:
[csharp]public partial class PageStrip : UserControl
{
public override ISite Site
{
get { return base.Site; }
set {
base.Site = value;

if (base.Site == null) return;

Global.ICCS = (IComponentChangeService)GetService(typeof(IComponentChangeService));
Global.ISS = (ISelectionService)GetService(typeof(ISelectionService));
Global.IDH = (IDesignerHost)GetService(typeof(IDesignerHost));
}
}
}[/csharp]
Is working for now...
 
Back
Top