다음을 통해 공유


ServiceProvider Class

Provides a unified service provider for managed VSPackages.

This API is not CLS-compliant. 

Namespace:  Microsoft.VisualStudio.Shell
Assemblies:   Microsoft.VisualStudio.Shell (in Microsoft.VisualStudio.Shell.dll)
  Microsoft.VisualStudio.Shell.10.0 (in Microsoft.VisualStudio.Shell.10.0.dll)
  Microsoft.VisualStudio.Shell.9.0 (in Microsoft.VisualStudio.Shell.9.0.dll)

Syntax

‘선언
<CLSCompliantAttribute(False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class ServiceProvider _
    Implements IServiceProvider, IDisposable, IObjectWithSite
‘사용 방법
Dim instance As ServiceProvider
[CLSCompliantAttribute(false)]
[ComVisibleAttribute(true)]
public sealed class ServiceProvider : IServiceProvider, 
    IDisposable, IObjectWithSite
[CLSCompliantAttribute(false)]
[ComVisibleAttribute(true)]
public ref class ServiceProvider sealed : IServiceProvider, 
    IDisposable, IObjectWithSite
[<SealedAttribute>]
[<CLSCompliantAttribute(false)>]
[<ComVisibleAttribute(true)>]
type ServiceProvider =  
    class
        interface IServiceProvider
        interface IDisposable
        interface IObjectWithSite
    end
public final class ServiceProvider implements IServiceProvider, IDisposable, IObjectWithSite

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.

참고

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(Object) method is ignored if the site does not implement IServiceProvider.)

Inheritance Hierarchy

System.Object
  Microsoft.VisualStudio.Shell.ServiceProvider

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

ServiceProvider Members

Microsoft.VisualStudio.Shell Namespace