Все мои строки подключения добавляются в мое приложение-функцию Azure через портал Azure. В функции http я могу получить к ним доступ, добавив IConfiguration в мой конструктор:
private readonly ILogger _logger;
private readonly IConfiguration _configuration;
public Update(ILogger logger, IConfiguration configuration)
{
_logger = logger;
_configuration = configuration;
}
Вот как я могу получить доступ к строке подключения:
_configuration.GetConnectionString("MyConnectionString")
Но как мне получить к ним доступ в устойчивой функции? Моя устойчивая функция запуска не имеет конструктора (статического класса):
public static class MyFunction
{
[Function(nameof(MyFunction))]
public static async Task RunOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
ILogger logger = context.CreateReplaySafeLogger(nameof(MyFunction));
logger.LogInformation("Saying hello.");
var outputs = new List();
// Replace name and input with values relevant for your Durable Functions Activity
outputs.Add(await context.CallActivityAsync(nameof(SayHello), "Tokyo"));
outputs.Add(await context.CallActivityAsync(nameof(SayHello), "Seattle"));
outputs.Add(await context.CallActivityAsync(nameof(SayHello), "London"));
// returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
return outputs;
}
[Function(nameof(SayHello))]
public static string SayHello([ActivityTrigger] string name, FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("SayHello");
logger.LogInformation("Saying hello to {name}.", name);
return $"Hello {name}!";
}
[Function("MyFunction_HttpStart")]
public static async Task HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
[DurableClient] DurableTaskClient client,
FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("MyFunction_HttpStart");
// Function input comes from the request content.
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
nameof(MyFunction));
logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);
// Returns an HTTP 202 response with an instance management payload.
// See https://learn.microsoft.com/azure/azure ... hestration
return await client.CreateCheckStatusResponseAsync(req, instanceId);
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... e-function
Как получить строку подключения в устойчивой функции Azure ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как получить текущий объект в изолированной модели устойчивой функции Azure
Anonymous » » в форуме C# - 0 Ответы
- 31 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Использование ConcurrentQueue в устойчивой функции Azure с взаимодействием с Dataverse
Anonymous » » в форуме C# - 0 Ответы
- 14 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Использование ConcurrentQueue в устойчивой функции Azure с взаимодействием с Dataverse
Anonymous » » в форуме C# - 0 Ответы
- 15 Просмотры
-
Последнее сообщение Anonymous
-