In-process and isolated functions
Last modified on Wed 28 Sep 2022

Differences:

For more info read here.

.NET 6 functions support both in-process and out-of-process options, but out-of-process does not support all bindings and features supported in in-process. In .Net 7 out-of-process will support full set of features so out-of-process will be the only supported option. To find out more read here.

Move from in-process to isolated function

When you want to move from in-process azure function to isolated azure function, the first thing you need to do is set OutputType property in your .csproj file to Exe. Then, change your FUNCTIONS_WORKER_RUNTIME app setting in local.settings.json to dotnet-isolated. At this point, your project won't build. Have no fear, you just need to add startup code.

Creating Host

Now you need to write your startup code to make the functions available to the host. In order to do that you will require three packages to be installed:

Now add Program.cs file, delete everything and write (copy and paste) the following code:

using Microsoft.Extensions.Hosting;ยง

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .Build();

await host.RunAsync();

Dependency Injection

If you use dependency injection into a function app, you just need to add a call to the ConfigureServices method on your host builder:

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices(services =>
    {
        services.AddScoped<IService, Service>();
    })
    .Build();

host.Run();

At this point, you can go ahead and remove Microsoft.NET.Sdk.Functions and any package reference to Azure Functions or WebJobs that don't include the term Worker, because they are meant to be used with in-process function apps.

Rebuilding Trigger Functions

The first thing you need to do is install the package Microsoft.Azure.Functions.Worker.Extensions.Http, which will give you access to the types required by your HTTP Trigger function. Then, make the following changes:

This means, for example, your HTTP trigger function should look like this:

[Function("YourFunction")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
{
    // your logic...

    return req.CreateResponse(HttpStatusCode.OK);
}