Accessing IServiceProvider with the Whidbey Managed Package Framework

In the Whidbey Managed Package Framework in VSIP there's a few different base classes that hold an IServiceProvider interface pointer.  This is usually stuffed into a ServiceProvider class and exposed via a protected GetService method on the class.

For WindowPane (or ToolWindowPane) this allows the internal implementation to get to VS services.  The problem is that most code would like to embed a standard .NET WinForm.  This is what the Package Wizard generates for you, but the user control doesn't have any mechanism to get to the Managed Package Framework itself.

There are two easy ways around this:

1) Send the IServiceProvider interface pointer to the user control.  (May sure you property dispose of the interface pointer in order to get the proper ref counting on the unmanaged side.)

2) Expose a GetVSService public/friend method which forwards the request directly to the protected GetService method.  The user control simply needs to have a refernce to the parent WindowPane (or ToolWindowPane).

I think #2 is the easiest to implement.

I hope this helps.

Skip to main content