我有功能应用程序,并在一个帮助程序类,准备一个文件并存储它为我想要读取项目文件
我尝试了很多方法,例如(AppDomain,AppContext,....等)和许多其他方法,并且因为它是无服务器的,所以program.cs与运行它的函数位于不同的目录中。我想要的是WebRoot目录。
我发现这个https://github.com/Azure/azure-functions-host/wiki/Retrieving-information-about-the-currently-running-function,这给了我想要的正确路径,使用FunctionAppDirectory的wwwroot。
问题是我需要将ExecutionContext传递给run函数,然后我需要将它传递给Helper类,我无法直接从helper类中读取它。我在多个地方都有这个。
我如何在应用程序/类中全局获取它。
谢谢。
解决问题的一种方法是
public interface IExecutionContext
{
Guid InvocationId { get; set; }
string FunctionName { get; set; }
string FunctionDirectory { get; set; }
string FunctionAppDirectory { get; set; }
}
public class FunctionAppExecutionContext : ExecutionContext, IExecutionContext
{
}
services.AddSingleton<IExecutionContext, FunctionAppExecutionContext>();
然后,在您的帮助程序类中,使用该接口隐藏实现。在这种情况下,函数SDKs ExecutionContext。重复类实现步骤以实现其他库的类。