This topic has not yet been rated - Rate this topic

ServiceProvider Class

Provides a unified service provider for managed VSPackages.

System.Object
  Microsoft.VisualStudio.Shell.ServiceProvider

Namespace:  Microsoft.VisualStudio.Shell
Assembly:  Microsoft.VisualStudio.Shell.12.0 (in Microsoft.VisualStudio.Shell.12.0.dll)
[ComVisibleAttribute(true)]
public sealed class ServiceProvider : IServiceProvider, 
	IDisposable, IObjectWithSite

The ServiceProvider type exposes the following members.

  NameDescription
Public methodServiceProvider(IServiceProvider)Initializes a instance with an existing IServiceProvider interface.
Public methodServiceProvider(IServiceProvider, Boolean)Initializes a new instance of the ServiceProvider class with an existing IServiceProvider object and optionally passes all requests to the underlying service provider.
Top
  NameDescription
Public propertyStatic memberGlobalProviderGets the global service provider for the calling thread.
Top
  NameDescription
Public methodStatic memberCreateFromSetSiteCreate a new ServiceProvider for the given site.
Public methodDisposeReleases the resources used by the ServiceProvider object.
Public methodEqualsDetermines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetService(Guid)Gets the specified service from the unmanaged service provider.
Public methodGetService(Type)Gets type-based services from the unmanaged service provider.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodQueryService(Guid, Object)Gets type-based services from the unmanaged service provider, with an option to prevent the error being sent to the shell.
Public methodQueryService(Type, Object)Gets type-based services from the unmanaged service provider, with an option to prevent the error being sent to the shell.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Explicit interface implemetationPrivate methodIObjectWithSite.GetSiteGets the current site object to resolve services.
Explicit interface implemetationPrivate methodIObjectWithSite.SetSiteSets the site object to resolve services.
Top

This class provides a unified service provider for managed VSPackages. It implements IServiceProvider and takes an instance of IServiceProvider as a constructor argument.

This class supports both GUID and type based lookups. It also checks for common native implementation pitfalls, such as objects that do not implement the IUnknown interface or that require a specific IID along with a matching SID.

This class also provides debugging support in the debug version of the .NET Framework (also known as a "checked" version). Setting the tracing switch TRACESERVICE to TraceVerbose causes all service requests to be output to the debug listener.

In addition, ServiceProvider tests for certain conditions when forwarding a service request to native code. Managed code requires the IUnknown interface when resolving services, but most native queries do not. If an unmanaged service cannot be obtained through an IID of IUnknown, an additional call is made in checked builds with the SID used in place of the IID. ServiceProvider raises an assert if the SID query succeeds.

NoteNote

Returning the result of a successful SID query in a checked build causes a different behavior in the debug and retail builds of the VSPackage, so an assert is raised instead.

In addition to translating service requests to the COM service provider, the ServiceProvider class offers the following non-replaceable services:

IServiceProvider

Provides access to the native COM service provider object. The service provider object can be used to directly query for other interfaces.

IObjectWithSite

Provides a way to replace the COM service provider. In many places within Visual Studio an object is first given one site, and later another, more localized site. The more localized site can be passed through to the service provider's IObjectWithSite implementation to create a single point of contact for services. (The SetSite method is ignored if the site does not implement IServiceProvider.)

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.