ServiceCreatorCallback Delegar

Definição

Fornece um mecanismo de retorno de chamada que pode criar uma instância de um serviço sob demanda.

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 

Parâmetros

container
IServiceContainer

O contêiner de serviço que solicitou a criação do serviço.

serviceType
Type

O tipo do serviço a ser criado.

Valor Retornado

O serviço especificado por serviceType ou então null, se o serviço não pôde ser criado.

Atributos

Exemplos

O exemplo de código a seguir mostra como publicar um serviço usando uma função de retorno de chamada.

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

Comentários

ServiceCreatorCallback fornece um mecanismo para publicar serviços que você pode solicitar que tenham criado quando necessário, em vez do serviço sendo criado imediatamente quando o designer é carregado. Você poderá usar uma função de retorno de chamada se o serviço não for essencial e não puder ser usado. Um serviço publicado usando um ServiceCreatorCallback não usará tantos recursos adicionais se não for solicitado e criado. Para usar uma função de retorno de chamada para publicar seu serviço, passe um ServiceCreatorCallback para o AddService método de um IServiceContainer.

Métodos de Extensão

GetMethodInfo(Delegate)

Obtém um objeto que representa o método representado pelo delegado especificado.

Aplica-se a

Confira também