I am following this post, and implemented the Startup class so that I can inject my services in the constructor, but the service instance is always null and I am getting Object reference not set to an instance of an object when I run the application.
Below is my Startup class.
[assembly: FunctionsStartup(typeof(Backup.Functions.Startup))]
namespace Backup.Functions {
public class Startup: FunctionsStartup {
public override void Configure(IFunctionsHostBuilder builder) {
builder.Services.AddSingleton < IBlobService,
BlobService > ();
}
}
}
My Function code is as below.
public class DeleteDailyBlobs {
private static IBlobService _blobService;
public DeleteDailyBlobs(IBlobService blobService) {
_blobService = blobService;
}
[FunctionName("DeleteDailyBlobs")]
public static void Run([TimerTrigger("0/3 * * * * *")] TimerInfo myTimer, ILogger log) {
if (_blobService.PerformTasks().GetAwaiter().GetResult()) {
log.LogInformation(SuccessMessages.FunctionExecutedSuccessfully);
}
else {
log.LogError(ErrorMessages.SomethingBadHappened);
}
}
}
Here the _blobService is always null.

