I've read and asked some questions on how to use DI using WebJob and especially Triggered Webjobs.
- SimpleInjector - Azure WebJob with TimerTrigger - Register IDisposable
- Dependency injection using Azure WebJobs SDK?
I still try to figure out how to integrate gracefully DI in triggered webjobs and @Steven asked me a good question :
Isn't there a way to wrap the execution of your service in some scope? For instance, MVC and Web API have an IDependencyScope abstraction for this. This notifies the starting and ending of a request. To be able to do scoping, you either need to have such interception point or you need to be able to wrap the call to JobActivator.
I know that I can start a scope inside my triggered function but I would like to know if there are any point of extensibility in the sdk that allow us to do scoping ?
Thanks.
I've opened an request Add IDependencyScope to handle scoping to the Azure Webjob team.
I've create a small library to gather classes around Azure Webjobs and SimpleInjector :
For QueueTrigger and ServiceBustrigger, I've come accross these solutions :
ServiceBusTrigger (from this answer: https://stackoverflow.com/a/33759649/4167200):
You can use your custom MessagingProvider in your JobHostConfiguration like
QueueTrigger:
You can use your custom IQueueProcessorFactory in your JobHostConfiguration like this: