Все мои строки подключения добавляются в мое приложение-функцию 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#
Место общения программистов C#
-
Anonymous
1728444611
Anonymous
Все мои строки подключения добавляются в мое приложение-функцию 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-functions/durable/durable-functions-http-api#start-orchestration
return await client.CreateCheckStatusResponseAsync(req, instanceId);
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79067536/how-do-i-get-my-connection-string-in-an-azure-durable-function[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия