Azure Functions Dependency Injection: Register Services and Typed HttpClients

Azure Functions supports dependency injection in both the isolated worker and in-process models, but their startup and registration patterns differ. The isolated worker uses the .NET host builder, while in-process apps use Functions startup configuration.

Overview

Configure dependency injection in Azure Functions, register application services and use IHttpClientFactory for resilient outbound HTTP calls.

Implementation guide

  1. Confirm whether the app uses the isolated worker or in-process model; follow only the matching startup pattern.
  2. Register application services in the host startup pipeline with appropriate lifetimes.
  3. Use AddHttpClient for outbound HTTP dependencies rather than creating a new HttpClient for every invocation.
  4. Keep function classes focused on trigger binding and orchestration; move business logic into injectable services.
  5. Test service construction locally and confirm required settings exist in the deployed environment.

Code example

// .NET isolated worker Program.cs
var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices(services =>
    {
        services.AddHttpClient<IInventoryClient, InventoryClient>();
        services.AddScoped<IOrderProcessor, OrderProcessor>();
    })
    .Build();
host.Run();

Common pitfalls

  • Do not mix isolated-worker and in-process dependency-injection APIs.
  • Avoid capturing transient or scoped services in long-lived singletons.
  • Configure timeouts and retry policies deliberately for outbound calls.

Conclusion

Use the documented platform behaviour as the contract, validate the design with realistic traffic and failure scenarios, and keep operational configuration under version control where appropriate.