I currently checking what needs to be done to migrate a dotnet core In-process azure function v3 to a dotnet coe Out-of-process/.NET Isolated azure function.
In my project the IHttpContextAccessor
is used to get the HttpContext
in some places. I tried to get the IHttpContextAccessor
in the function, but it is null.
Is it possible to get the IHttpContextAccessor
in Azure Function Isolated or do I need to change the code to no longer use it?
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(s =>
{
s.AddHttpContextAccessor();
})
.Build();
private readonly IHttpContextAccessor httpContextAccessor;
public Function1(IHttpContextAccessor httpContextAccessor)
{
this.httpContextAccessor = httpContextAccessor;
}
[Function("Function1")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req,
FunctionContext executionContext)
{
var logger = executionContext.GetLogger("Function1");
logger.LogInformation(httpContextAccessor.HttpContext.Request.Scheme);