共用方式為


ServiceCreatorCallback 代理人

定義

提供回呼 (Callback) 機制,這個回呼機制可以視需要建立服務的執行個體。

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

參數

container
IServiceContainer

要求服務建立的服務容器 (Container)。

serviceType
Type

要建立的服務類型。

傳回值

serviceType 所指定的服務,或 null (如果無法建立服務)。

屬性

範例

下列程式代碼範例示範如何使用回呼函式發佈服務。

// 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 所發行的服務不會使用許多其他資源。 若要使用回呼函式發佈您的服務,請將 傳遞 ServiceCreatorCallbackAddServiceIServiceContainer方法。

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。

適用於

另請參閱