I have function Apps, and in a helper class that is going to prepare a file and store it for me i want to read the project file
I tried many ways, such as (AppDomain, AppContext, .... etc) and many others, and as it is serverless, the program.cs is at different directory from the function where it is running. what i want is the WebRoot directory.
i found this https://github.com/Azure/azure-functions-host/wiki/Retrieving-information-about-the-currently-running-function and this is giving me the correct path i want, the wwwroot by using FunctionAppDirectory.
the issue is I need to pass the ExecutionContext to the run function, and then i need to pass it to the Helper class, I cannot read it directly from the helper classes. and i have this in multiple places.
How i can get this globally across the application/Classes.
thanks.
One way to solve your problem would be to
Define a global interface:
public interface IExecutionContext
{
Guid InvocationId { get; set; }
string FunctionName { get; set; }
string FunctionDirectory { get; set; }
string FunctionAppDirectory { get; set; }
}
Add implementation for Function App:
public class FunctionAppExecutionContext : ExecutionContext, IExecutionContext
{
}
Add DI configuration for Function App(optional):
services.AddSingleton<IExecutionContext, FunctionAppExecutionContext>();
Then, in your helper classes, use the interface to hide the implementation. Which, in this case, is Functions SDKs ExecutionContext. Repeat the class implementation steps to implement classes for other libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With