Table of Contents

Class TemporalHostingServiceCollectionExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
Temporalio.Extensions.Hosting.dll

Temporal extensions for IServiceCollection.

public static class TemporalHostingServiceCollectionExtensions
Inheritance
TemporalHostingServiceCollectionExtensions
Inherited Members

Methods

AddHostedTemporalWorker(IServiceCollection, string, string)

Add a hosted Temporal worker service as a IHostedService that expects an injected ITemporalClient (or the returned builder can have client options populated). Use AddHostedTemporalWorker(IServiceCollection, string, string, string, string) to not expect an injected instance and instead connect to a client on worker start. The worker service will be registered as a singleton. The result is an options builder that can be used to configure the service.

[Obsolete("Use the AddHostedTemporalWorker overload with WorkerDeploymentOptions instead")]
public static ITemporalWorkerServiceOptionsBuilder AddHostedTemporalWorker(this IServiceCollection services, string taskQueue, string buildId)

Parameters

services IServiceCollection

Service collection to create hosted worker on.

taskQueue string

Task queue for the worker.

buildId string

Build ID for the worker. It is important to set build ID here and not later via configure options. This is because the combination of task queue and build ID make up the unique identifier for a worker in the service collection.

Returns

ITemporalWorkerServiceOptionsBuilder

Options builder to configure the service.

AddHostedTemporalWorker(IServiceCollection, string, string, string, string)

Add a hosted Temporal worker service as a IHostedService that contains its own client that connects with the given target and namespace. To use an injected ITemporalClient, use AddHostedTemporalWorker(IServiceCollection, string, string). The worker service will be registered as a singleton. The result is an options builder that can be used to configure the service.

[Obsolete("Use the AddHostedTemporalWorker overload with WorkerDeploymentOptions instead")]
public static ITemporalWorkerServiceOptionsBuilder AddHostedTemporalWorker(this IServiceCollection services, string clientTargetHost, string clientNamespace, string taskQueue, string buildId)

Parameters

services IServiceCollection

Service collection to create hosted worker on.

clientTargetHost string

Client target host to connect to when starting the worker.

clientNamespace string

Client namespace to connect to when starting the worker.

taskQueue string

Task queue for the worker.

buildId string

Build ID for the worker. It is important to set build ID here and not later via configure options. This is because the combination of task queue and build ID make up the unique identifier for a worker in the service collection.

Returns

ITemporalWorkerServiceOptionsBuilder

Options builder to configure the service.

AddHostedTemporalWorker(IServiceCollection, string, string, string, WorkerDeploymentOptions?)

Add a hosted Temporal worker service as a IHostedService that contains its own client that connects with the given target and namespace. To use an injected ITemporalClient, use AddHostedTemporalWorker(IServiceCollection, string, string). The worker service will be registered as a singleton. The result is an options builder that can be used to configure the service.

public static ITemporalWorkerServiceOptionsBuilder AddHostedTemporalWorker(this IServiceCollection services, string clientTargetHost, string clientNamespace, string taskQueue, WorkerDeploymentOptions? deploymentOptions = null)

Parameters

services IServiceCollection

Service collection to create hosted worker on.

clientTargetHost string

Client target host to connect to when starting the worker.

clientNamespace string

Client namespace to connect to when starting the worker.

taskQueue string

Task queue for the worker.

deploymentOptions WorkerDeploymentOptions

Deployment options for the worker. It is important to set deployment options here and not later via configure options. This is because the combination of task queue and deployment version make up the unique identifier for a worker in the service collection.

Returns

ITemporalWorkerServiceOptionsBuilder

Options builder to configure the service.

AddHostedTemporalWorker(IServiceCollection, string, WorkerDeploymentOptions?)

Add a hosted Temporal worker service as a IHostedService that expects an injected ITemporalClient (or the returned builder can have client options populated). Use AddHostedTemporalWorker(IServiceCollection, string, string, string, string) to not expect an injected instance and instead connect to a client on worker start. The worker service will be registered as a singleton. The result is an options builder that can be used to configure the service.

public static ITemporalWorkerServiceOptionsBuilder AddHostedTemporalWorker(this IServiceCollection services, string taskQueue, WorkerDeploymentOptions? deploymentOptions = null)

Parameters

services IServiceCollection

Service collection to create hosted worker on.

taskQueue string

Task queue for the worker.

deploymentOptions WorkerDeploymentOptions

Deployment options for the worker. It is important to set deployment options here and not later via configure options. This is because the combination of task queue and deployment version make up the unique identifier for a worker in the service collection.

Returns

ITemporalWorkerServiceOptionsBuilder

Options builder to configure the service.

AddTemporalClient(IServiceCollection, Action<TemporalClientConnectOptions>)

Adds a singleton ITemporalClient via TryAddSingleton<TService>(IServiceCollection, Func<IServiceProvider, TService>) using a lazy client created with CreateLazy(TemporalClientConnectOptions). The action can be used to configure the client as can any options approach that alters TemporalClientConnectOptions. If a logging factory is on the container, it will be set on the client.

public static IServiceCollection AddTemporalClient(this IServiceCollection services, Action<TemporalClientConnectOptions> configureClient)

Parameters

services IServiceCollection

Service collection to add Temporal client to.

configureClient Action<TemporalClientConnectOptions>

Action to configure client options.

Returns

IServiceCollection

The given service collection for chaining.

AddTemporalClient(IServiceCollection, string?, string?)

Adds a singleton ITemporalClient via TryAddSingleton<TService>(IServiceCollection, Func<IServiceProvider, TService>) using a lazy client created with CreateLazy(TemporalClientConnectOptions). The resulting builder can be used to configure the client as can any options approach that alters TemporalClientConnectOptions. If a logging factory is on the container, it will be set on the client.

public static OptionsBuilder<TemporalClientConnectOptions> AddTemporalClient(this IServiceCollection services, string? clientTargetHost = null, string? clientNamespace = null)

Parameters

services IServiceCollection

Service collection to add Temporal client to.

clientTargetHost string

If set, the host to connect to.

clientNamespace string

If set, the namespace for the client.

Returns

OptionsBuilder<TemporalClientConnectOptions>

Options builder for setting client options.

Remarks

This client can be used with TemporalWorkerService from AddHostedTemporalWorker but not TemporalWorker directly because lazy unconnected clients can't be used directly with those workers.