Search code examples
c#azure-functionsdotnet-isolated

What is the purpose of IJobHostContextFactory/JobHostContextFactory?


We are in the process of migrating Azure Functions to isolated in our project. During this process I came across an implementation of Microsoft.Azure.WebJobs.Host.Executors.IJobHostContextFactory. But no one could tell me what it is needed for.

I haven't found any documentation for it. Can anyone of you help me?

What is the purpose of Microsoft.Azure.WebJobs.Host.Executors.IJobHostContextFactory or its implementation Microsoft.Azure.WebJobs.Host.Executors.JobHostContextFactory?

Do I need it for isolated functions?


Edit:

I looked into it again and found that when I start an In-Process function the ServiceCollection contains a reference to IJobHostContextFactory. However, when I start an isolated function, the ServiceCollection does not contain a reference. That is, for isolated functions, the JobHostContextFactory does not seem to be needed.


Solution

  • It's an interface that passes the Ronseal challenge: ("it does exactly what it says on the tin"): it creates instances of JobHostContext objects, which are used/consumed by IFunctionInstance objects which represent your functions.

    You can see this in the source-code of JobHost available here: https://github.com/Azure/azure-webjobs-sdk/blob/dev/src/Microsoft.Azure.WebJobs.Host/JobHost.cs

    As it's a service interface and default implementation that's built-in to the WebJobs SDK you don't need to implement it yourself - unless you really need to customize how JobHostContext objects are created for some reason (e.g. if you're using a DI system that's not compatible with Microsoft.Extensions.DependencyInjection, I guess).