You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/logic-apps/create-run-custom-code-functions.md
+107-4Lines changed: 107 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,9 @@ services: azure-logic-apps
5
5
ms.suite: integration
6
6
ms.reviewers: estfan, kewear, azla
7
7
ms.topic: how-to
8
+
ai.usage: ai-assisted
8
9
ms.update-cycle: 1095-days
9
-
ms.date: 04/07/2026
10
+
ms.date: 04/10/2026
10
11
ms.custom:
11
12
- devx-track-dotnet
12
13
- sfi-image-nochange
@@ -323,7 +324,7 @@ After you confirm that your code compiles and your logic app project contains th
323
324
324
325
| Operation | Description |
325
326
|-----------|-------------|
326
-
| Trigger | The built-in [Request trigger named **When a HTTP request is received**](../connectors/connectors-native-reqres.md). |
327
+
| Trigger | The built-in [Request trigger named **When an HTTP request is received**](../connectors/connectors-native-reqres.md). |
327
328
| Action | The built-in action named **Call a local function in this logic app**. |
328
329
| Action | The built-in [Response action named **Response**](../connectors/connectors-native-reqres.md) that you use to reply to the caller only when you use the **Request** trigger. |
329
330
@@ -402,6 +403,108 @@ Deploy your custom functions the same way you deploy your logic app project. Whe
402
403
403
404
For more information, see [Deploy Standard workflows from Visual Studio Code to Azure](create-single-tenant-workflows-visual-studio-code.md#deploy-azure).
404
405
406
+
## Dependency injection
407
+
408
+
When you choose **.NET 8**, custom .NET code in Standard workflows supports *dependency injection (DI)*. This capability lets you register services once, which makes them automatically available to your custom code functions at runtime, rather than create dependencies inside each function.
409
+
410
+
> [!NOTE]
411
+
>
412
+
> Only .NET 8 custom code projects in Visual Studio Code support dependency injection.
413
+
414
+
Without dependency injection, custom code functions often:
415
+
416
+
- Create service instances directly in the function.
417
+
- Duplicate logic across multiple functions or workflows.
418
+
- Mix business logic with setup and configuration code.
419
+
420
+
As workflows grow, custom code becomes harder to test, reuse, and maintain. With dependency injection, you can:
421
+
422
+
- Separate business logic from workflow execution.
423
+
- Reuse shared services across multiple custom code functions.
424
+
- Align custom code with standard .NET development patterns.
425
+
426
+
Custom code becomes more manageable in production workflows, especially when multiple workflows rely on the same logic.
427
+
428
+
### When to use dependency injection
429
+
430
+
If you have simple or one-off custom code functions, you probably don't need dependency injection. However, if your custom code has the following requirements, you might need to use dependency injection:
431
+
432
+
- Multiple workflows use or share the same custom code functions.
433
+
- Your custom code functions contain business or routing logic that changes over time.
434
+
- You require better testability or long‑term maintainability.
435
+
436
+
### How does dependency injection affect custom .NET functions
437
+
438
+
Dependency injection doesn't change how you call custom .NET functions or your workflow behavior. This capability only changes the underlying custom code structure but produces the same outcome. The following steps describe this process:
439
+
440
+
1. Azure Logic Apps loads your custom code project.
441
+
1. Azure Logic Apps instantiates, registers, and injects the required services into the function.
442
+
1. The function runs using the injected dependencies.
443
+
444
+
### Enable dependency injection
445
+
446
+
To use dependency injection with your custom .NET code, complete the following requirements:
447
+
448
+
1. When you create your custom code project, select **.NET 8**.
449
+
450
+
Only .NET 8 custom code projects support dependency injection.
451
+
452
+
1. In your project, add a `StartupConfiguration` class to define the list of dependencies. Implement the `IConfigureStartup` interface and register your dependencies by using `IServiceCollection`, for example:
The `IConfigureStartup` interface is defined in `Microsoft.Extensions.DependencyInjection`. For more information, see [StartupConfiguration.cs](https://github.com/wsilveiranz/CustomCode-Dependency-Injection/blob/master/OrderRouter/StartupConfiguration.cs)
474
+
475
+
1. In your custom code function class constructor, initialize the registered services by defining them as constructor parameters, rather than creating them inside the function, for example:
Beyond building and deploying your custom code project, you don't need to take any other steps, edit your workflow, or make any other setup changes in Azure Logic Apps to enable dependency injection.
497
+
498
+
For more information, see the [Custom Code Dependency Injection sample](https://github.com/wsilveiranz/CustomCode-Dependency-Injection/tree/master/FourthCoffeeServices/FourthCoffeeOrder).
499
+
500
+
## Bring your own NuGet packages
501
+
502
+
For NuGet-based custom code projects that use .NET 8, you can include and manage your own NuGet packages without having to resolve conflicts with dependencies used by the language worker host. Just directly add the assembly dependencies to the separate assembly location in your project. With the following exceptions, you can bring any .NET 8-compatible dependent assembly versions that your project needs:
0 commit comments