Skip to content

Commit ccbd80f

Browse files
Merge pull request #299400 from TimShererWithAquent/us424061-10
Freshness Edit: Azure Functions (10 of several)
2 parents 369c207 + 853f049 commit ccbd80f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

articles/azure-functions/functions-dotnet-dependency-injection.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: Use dependency injection in .NET Azure Functions
3-
description: Learn how to use dependency injection for registering and using services in .NET functions
3+
description: Learn how to use dependency injection for registering and using services in .NET Azure Functions, including setup, configuration, and best practices.
44

55
ms.topic: conceptual
66
ms.devlang: csharp
77
ms.custom: devx-track-csharp, devx-track-dotnet
8-
ms.date: 03/24/2021
8+
ms.date: 05/07/2025
99
ms.reviewer: jehollan
1010
---
1111
# Use dependency injection in .NET Azure Functions
@@ -16,7 +16,7 @@ Azure Functions supports the dependency injection (DI) software design pattern,
1616

1717
- Support for dependency injection begins with Azure Functions 2.x.
1818

19-
- Dependency injection patterns differ depending on whether your C# functions run [in-process](functions-dotnet-class-library.md) or [out-of-process](dotnet-isolated-process-guide.md).
19+
- Dependency injection patterns differ depending on whether your C# functions run [in-process](functions-dotnet-class-library.md) or [out-of-process](dotnet-isolated-process-guide.md).
2020

2121
> [!IMPORTANT]
2222
> The guidance in this article applies only to [C# class library functions](functions-dotnet-class-library.md), which run in-process with the runtime. This custom dependency injection model doesn't apply to [.NET isolated functions](dotnet-isolated-process-guide.md), which lets you run .NET functions out-of-process. The .NET isolated worker process model relies on regular ASP.NET Core dependency injection patterns. To learn more, see [Dependency injection](dotnet-isolated-process-guide.md#dependency-injection) in the .NET isolated worker process guide.
@@ -33,7 +33,7 @@ Before you can use dependency injection, you must install the following NuGet pa
3333

3434
## Register services
3535

36-
To register services, create a method to configure and add components to an `IFunctionsHostBuilder` instance. The Azure Functions host creates an instance of `IFunctionsHostBuilder` and passes it directly into your method.
36+
To register services, create a method to configure and add components to an `IFunctionsHostBuilder` instance. The Azure Functions host creates an instance of `IFunctionsHostBuilder` and passes it directly into your method.
3737

3838
> [!WARNING]
3939
> For function apps running in the Consumption or Premium plans, modifications to configuration values used in triggers can cause scaling errors. Any changes to these properties by the `FunctionsStartup` class results in a function app startup error.
@@ -138,11 +138,11 @@ Application Insights is added by Azure Functions automatically.
138138

139139
> [!WARNING]
140140
> - Don't add `AddApplicationInsightsTelemetry()` to the services collection, which registers services that conflict with services provided by the environment.
141-
> - Don't register your own `TelemetryConfiguration` or `TelemetryClient` if you are using the built-in Application Insights functionality. If you need to configure your own `TelemetryClient` instance, create one via the injected `TelemetryConfiguration` as shown in [Log custom telemetry in C# functions](functions-dotnet-class-library.md?tabs=v2%2Ccmd#log-custom-telemetry-in-c-functions).
141+
> - Don't register your own `TelemetryConfiguration` or `TelemetryClient` if you're using the built-in Application Insights functionality. If you need to configure your own `TelemetryClient` instance, create one via the injected `TelemetryConfiguration` as shown in [Log custom telemetry in C# functions](functions-dotnet-class-library.md?tabs=v2%2Ccmd#log-custom-telemetry-in-c-functions).
142142
143143
### ILogger\<T\> and ILoggerFactory
144144

145-
The host injects `ILogger<T>` and `ILoggerFactory` services into constructors. However, by default these new logging filters are filtered out of the function logs. You need to modify the `host.json` file to opt in to extra filters and categories.
145+
The host injects `ILogger<T>` and `ILoggerFactory` services into constructors. However, by default these new logging filters are filtered out of the function logs. You need to modify the `host.json` file to opt in to extra filters and categories.
146146

147147
The following example demonstrates how to add an `ILogger<HttpTrigger>` with logs that are exposed to the host.
148148

@@ -202,7 +202,7 @@ If there are other services you want to take a dependency on, [create an issue a
202202

203203
### Overriding host services
204204

205-
Overriding services provided by the host is currently not supported. If there are services you want to override, [create an issue and propose them on GitHub](https://github.com/azure/azure-functions-host).
205+
Overriding services provided by the host is currently not supported. If there are services you want to override, [create an issue and propose them on GitHub](https://github.com/azure/azure-functions-host).
206206

207207
## Working with options and settings
208208

@@ -220,6 +220,7 @@ public class MyOptions
220220
```
221221

222222
And a `local.settings.json` file that might structure the custom setting as follows:
223+
223224
```json
224225
{
225226
"IsEncrypted": false,

0 commit comments

Comments
 (0)