ServiceProvider ServiceProvider ServiceProvider ServiceProvider Class

Definition

Provides a unified service provider for managed VSPackages.

public ref class ServiceProvider sealed : IDisposable, IServiceProvider, Microsoft::VisualStudio::OLE::Interop::IObjectWithSite
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ServiceProvider : IDisposable, IServiceProvider, Microsoft.VisualStudio.OLE.Interop.IObjectWithSite
type ServiceProvider = class
    interface IServiceProvider
    interface IDisposable
    interface IObjectWithSite
Public NotInheritable Class ServiceProvider
Implements IDisposable, IObjectWithSite, IServiceProvider
Inheritance
ServiceProviderServiceProviderServiceProviderServiceProvider
Attributes
Implements

Remarks

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.

Note

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.)

Constructors

ServiceProvider(IServiceProvider) ServiceProvider(IServiceProvider) ServiceProvider(IServiceProvider) ServiceProvider(IServiceProvider)

Initializes a instance with an existing IServiceProvider interface.

ServiceProvider(IServiceProvider, Boolean) ServiceProvider(IServiceProvider, Boolean) ServiceProvider(IServiceProvider, Boolean) ServiceProvider(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.

Properties

GlobalProvider GlobalProvider GlobalProvider GlobalProvider

Gets the global service provider for the calling thread.

Methods

CreateFromSetSite(IServiceProvider) CreateFromSetSite(IServiceProvider) CreateFromSetSite(IServiceProvider) CreateFromSetSite(IServiceProvider)

Create a new ServiceProvider for the given site.

Dispose() Dispose() Dispose() Dispose()

Releases the resources used by the ServiceProvider object.

GetGlobalServiceAsync(Type) GetGlobalServiceAsync(Type) GetGlobalServiceAsync(Type) GetGlobalServiceAsync(Type)
GetGlobalServiceAsync(Type, Boolean) GetGlobalServiceAsync(Type, Boolean) GetGlobalServiceAsync(Type, Boolean) GetGlobalServiceAsync(Type, Boolean)
GetGlobalServiceAsync<TService,TInterface>() GetGlobalServiceAsync<TService,TInterface>() GetGlobalServiceAsync<TService,TInterface>() GetGlobalServiceAsync<TService,TInterface>()
GetGlobalServiceAsync<TService,TInterface>(Boolean) GetGlobalServiceAsync<TService,TInterface>(Boolean) GetGlobalServiceAsync<TService,TInterface>(Boolean) GetGlobalServiceAsync<TService,TInterface>(Boolean)
GetService(Guid) GetService(Guid) GetService(Guid) GetService(Guid)

Gets the specified service from the unmanaged service provider.

GetService(Type) GetService(Type) GetService(Type) GetService(Type)

Gets type-based services from the unmanaged service provider.

QueryService(Guid, Object) QueryService(Guid, Object) QueryService(Guid, Object) QueryService(Guid, Object)

Gets type-based services from the unmanaged service provider, with an option to prevent the error being sent to the shell.

QueryService(Type, Object) QueryService(Type, Object) QueryService(Type, Object) QueryService(Type, Object)

Gets type-based services from the unmanaged service provider, with an option to prevent the error being sent to the shell.

Explicit Interface Implementations

IObjectWithSite.GetSite(Guid, IntPtr) IObjectWithSite.GetSite(Guid, IntPtr) IObjectWithSite.GetSite(Guid, IntPtr) IObjectWithSite.GetSite(Guid, IntPtr)

Gets the current site object to resolve services.

IObjectWithSite.SetSite(Object) IObjectWithSite.SetSite(Object) IObjectWithSite.SetSite(Object) IObjectWithSite.SetSite(Object)

Sets the site object to resolve services.

Extension Methods

FindAncestor<TElementType>(TElementType, Func<TElementType,TElementType>, Func<TElementType,Boolean>) FindAncestor<TElementType>(TElementType, Func<TElementType,TElementType>, Func<TElementType,Boolean>) FindAncestor<TElementType>(TElementType, Func<TElementType,TElementType>, Func<TElementType,Boolean>) FindAncestor<TElementType>(TElementType, Func<TElementType,TElementType>, Func<TElementType,Boolean>)
FindAncestor<TAncestorType,TElementType>(TElementType, Func<TElementType,TElementType>) FindAncestor<TAncestorType,TElementType>(TElementType, Func<TElementType,TElementType>) FindAncestor<TAncestorType,TElementType>(TElementType, Func<TElementType,TElementType>) FindAncestor<TAncestorType,TElementType>(TElementType, Func<TElementType,TElementType>)

Microsoft internal use only.

FindAncestorOrSelf<TElementType>(TElementType, Func<TElementType,TElementType>, Func<TElementType,Boolean>) FindAncestorOrSelf<TElementType>(TElementType, Func<TElementType,TElementType>, Func<TElementType,Boolean>) FindAncestorOrSelf<TElementType>(TElementType, Func<TElementType,TElementType>, Func<TElementType,Boolean>) FindAncestorOrSelf<TElementType>(TElementType, Func<TElementType,TElementType>, Func<TElementType,Boolean>)
FindAncestorOrSelf<TAncestorType,TElementType>(TElementType, Func<TElementType,TElementType>) FindAncestorOrSelf<TAncestorType,TElementType>(TElementType, Func<TElementType,TElementType>) FindAncestorOrSelf<TAncestorType,TElementType>(TElementType, Func<TElementType,TElementType>) FindAncestorOrSelf<TAncestorType,TElementType>(TElementType, Func<TElementType,TElementType>)
IsAncestorOf<TElementType>(TElementType, TElementType, Func<TElementType,TElementType>) IsAncestorOf<TElementType>(TElementType, TElementType, Func<TElementType,TElementType>) IsAncestorOf<TElementType>(TElementType, TElementType, Func<TElementType,TElementType>) IsAncestorOf<TElementType>(TElementType, TElementType, Func<TElementType,TElementType>)

Microsoft internal use only.

Applies to