I am observing that the hashCode
of _serviceProvider
is the same throughout all the execution of the below function at an interval of 1 min.
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System;
namespace TestFunction
{
public class Function2
{
private readonly IServiceProvider _serviceProvider;
public Function2(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
[FunctionName("Function2")]
public void Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
{
var hashCode = _serviceProvider.GetHashCode();
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
}
Version:
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
FYI: I also compared the hashcode
of serviceProvider in an API
for two requests at the same endpoint but they are different.
Question: What is the lifetime of IServiceProvider in a Time Trigger Azure Functions?