in src/WebJobs.Extensions.DurableTask/DurableTaskExtension.cs [102:184]
public DurableTaskExtension(
IOptions<DurableTaskOptions> options,
ILoggerFactory loggerFactory,
INameResolver nameResolver,
IEnumerable<IDurabilityProviderFactory> orchestrationServiceFactories,
IApplicationLifetimeWrapper hostLifetimeService,
IDurableHttpMessageHandlerFactory durableHttpMessageHandlerFactory = null,
ILifeCycleNotificationHelper lifeCycleNotificationHelper = null,
IMessageSerializerSettingsFactory messageSerializerSettingsFactory = null,
#pragma warning disable CS0612 // Type or member is obsolete
IPlatformInformation platformInformationService = null,
#pragma warning restore CS0612 // Type or member is obsolete
IErrorSerializerSettingsFactory errorSerializerSettingsFactory = null,
#pragma warning disable CS0618 // Type or member is obsolete
IWebHookProvider webhookProvider = null,
#pragma warning restore CS0618 // Type or member is obsolete
ITelemetryActivator telemetryActivator = null)
{
this.extensionGuid = Guid.NewGuid();
// Options will be null in Functions v1 runtime - populated later.
this.Options = options?.Value ?? new DurableTaskOptions();
this.nameResolver = nameResolver ?? throw new ArgumentNullException(nameof(nameResolver));
this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
this.PlatformInformationService = platformInformationService ?? throw new ArgumentNullException(nameof(platformInformationService));
DurableTaskOptions.ResolveAppSettingOptions(this.Options, this.nameResolver);
ILogger logger = loggerFactory.CreateLogger(LoggerCategoryName);
this.TraceHelper = new EndToEndTraceHelper(logger, this.Options.Tracing.TraceReplayEvents, this.Options.Tracing.TraceInputsAndOutputs);
this.LifeCycleNotificationHelper = lifeCycleNotificationHelper ?? this.CreateLifeCycleNotificationHelper();
this.durabilityProviderFactory = GetDurabilityProviderFactory(this.Options, logger, orchestrationServiceFactories);
this.defaultDurabilityProvider = this.durabilityProviderFactory.GetDurabilityProvider();
this.isOptionsConfigured = true;
if (durableHttpMessageHandlerFactory == null)
{
durableHttpMessageHandlerFactory = new DurableHttpMessageHandlerFactory();
}
DurableHttpClientFactory durableHttpClientFactory = new DurableHttpClientFactory();
this.durableHttpClient = durableHttpClientFactory.GetClient(durableHttpMessageHandlerFactory);
this.MessageDataConverter = CreateMessageDataConverter(messageSerializerSettingsFactory);
this.ErrorDataConverter = this.CreateErrorDataConverter(errorSerializerSettingsFactory);
this.TypedCodeProvider = new TypedCodeProvider();
this.TypedCodeProvider.Initialize();
this.HttpApiHandler = new HttpApiHandler(this, logger);
// This line ensure every time we need the webhook URI, we get it directly from the
// function runtime, which has the most up-to-date knowledge about the site hostname.
Func<Uri> webhookDelegate = () => webhookProvider.GetUrl(this);
this.HttpApiHandler.RegisterWebhookProvider(
this.Options.WebhookUriProviderOverride ??
webhookDelegate);
this.HostLifetimeService = hostLifetimeService;
// The RPC server is started when the extension is initialized.
// The RPC server is stopped when the host has finished shutting down.
this.HostLifetimeService.OnStopped.Register(this.StopLocalHttpServer);
this.telemetryActivator = telemetryActivator;
this.telemetryActivator?.Initialize(logger);
// Starting with .NET isolated and Java, we have a more efficient out-of-process
// function invocation protocol. Other languages will use the existing protocol.
WorkerRuntimeType runtimeType = this.PlatformInformationService.GetWorkerRuntimeType();
if (runtimeType == WorkerRuntimeType.DotNetIsolated ||
runtimeType == WorkerRuntimeType.Java ||
runtimeType == WorkerRuntimeType.Custom)
{
this.OutOfProcProtocol = OutOfProcOrchestrationProtocol.MiddlewarePassthrough;
this.localGrpcListener = new LocalGrpcListener(this);
this.HostLifetimeService.OnStopped.Register(this.StopLocalGrpcServer);
}
else
{
this.OutOfProcProtocol = OutOfProcOrchestrationProtocol.OrchestratorShim;
}
}