ServiceCreatorCallback 代理人

定義

提供回呼 (Callback) 機制,這個回呼機制可以視需要建立服務的執行個體。Provides a callback mechanism that can create an instance of a service on demand.

public delegate System::Object ^ ServiceCreatorCallback(IServiceContainer ^ container, Type ^ serviceType);
[System.Runtime.InteropServices.ComVisible(true)]
public delegate object ServiceCreatorCallback(IServiceContainer container, Type serviceType);
type ServiceCreatorCallback = delegate of IServiceContainer * Type -> obj
Public Delegate Function ServiceCreatorCallback(container As IServiceContainer, serviceType As Type) As Object 

參數

container
IServiceContainer

要求服務建立的服務容器 (Container)。The service container that requested the creation of the service.

serviceType
Type

要建立的服務類型。The type of service to create.

傳回值

Object

serviceType 所指定的服務,或 null (如果無法建立服務)。The service specified by serviceType, or null if the service could not be created.

繼承
ServiceCreatorCallback
屬性

範例

下列程式碼範例示範如何使用回呼函數發行服務。The following code example shows how to publish a service using a callback function.

// The following code shows how to publish a service using a callback function.
// Creates a service creator callback.
ServiceCreatorCallback^ callback1 =
   gcnew ServiceCreatorCallback( this, &Sample::myCallBackMethod );

// Adds the service using its type and the service creator callback.
serviceContainer->AddService( myService::typeid, callback1 );
// The following code shows how to publish a service using a callback function.

// Creates a service creator callback.
ServiceCreatorCallback callback1 = 
new ServiceCreatorCallback(myCallBackMethod);

// Adds the service using its type and the service creator callback.
serviceContainer.AddService(typeof(myService), callback1);
' The following code shows how to publish a service using a callback function.

' Creates a service creator callback.
Dim callback1 As New ServiceCreatorCallback _
(AddressOf myCallBackMethod)
       
' Adds the service using its type and the service creator.
serviceContainer.AddService(GetType(myService), callback1)

備註

ServiceCreatorCallback提供一種機制來發行服務, 您可以要求在需要時加以建立, 而不是在設計工具載入時立即建立的服務。ServiceCreatorCallback provides a mechanism to publish services that you can request to have created when needed, rather than the service being created immediately when the designer loads. 如果服務不是必要的, 而且可能不會使用, 您可以使用回呼函數。You can use a callback function if the service is not essential and may not be used. 使用所發佈的服務不ServiceCreatorCallback會使用不需要的額外資源, 也不會建立。A service published by using a ServiceCreatorCallback does not use as many additional resources if it is not requested and created. 若要使用回呼函式ServiceCreatorCallback IServiceContainer來發行您的服務, 請將AddService傳遞至的方法。To use a callback function to publish your service, pass a ServiceCreatorCallback to the AddService method of an IServiceContainer.

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。Gets an object that represents the method represented by the specified delegate.

適用於

另請參閱