I am building an Azure WebJob that will run continuously. I want the WebJob to use the same style of DI as ASP.NET Core. I found this answer (Dependency injection using Azure WebJobs SDK?) on how to get DI/IoC working by using a custom IJobActivator. I also found this answer (Azure WebJobs - No functions found - How do I make a trigger-less job?) on using NoAutomaticTrigger to configure a continuously running Web Job.
The problem is that the NoAutomaticTrigger approach uses static methods, which is not compatible with DI/IoC. I assume that is because there is nothing that would cause the service with the NoAutomaticTrigger method to get resolved (like a queue message). I feel like ITypeLocator might be a path forward, but that is just a hunch.
The JobHost.Call method used in other NoAutomaticTrigger examples is limited to a static method. How do I have a service that is resolved via DI that gets resolved and called from a call on JobHost (or some other method) in Program.cs?
The solution that Iza Eddi-son Atsou suggested below works, with one wrinkle. I am used to registering my services via an interface on the service. Something like
serviceCollection.AddSingleton<IApplication, Application>();
The problem with this is that if the NoAutomaticTrigger attribute is on the interface, the SDK blows up. The solution is to add the attribute to the class, and register the class as itself.
serviceCollection.AddSingleton<Application>();
Once that change is made, the solution in the answer works great.