ServiceCreatorCallback 代理人
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供回呼 (Callback) 機制,這個回呼機制可以視需要建立服務的執行個體。
public delegate System::Object ^ ServiceCreatorCallback(IServiceContainer ^ container, Type ^ serviceType);
C#
public delegate object ServiceCreatorCallback(IServiceContainer container, Type serviceType);
C#
public delegate object? ServiceCreatorCallback(IServiceContainer container, Type serviceType);
C#
[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 );
C#
// 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 所發行的服務不會使用許多其他資源。 若要使用回呼函式發佈您的服務,請將 傳遞 ServiceCreatorCallback 至 AddService 的 IServiceContainer方法。
Get |
取得表示特定委派所代表之方法的物件。 |
產品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |