Azure / Azure/azure-functions-dotnet-worker
Documentation of Dependency Injection differences between in-process and isolated models
- Dominant language
- C#
- Stars
- 466
- Forks
- 215
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 7
Description
### What version of .NET does your existing project use?
.NET 6 In-Process
### What version of .NET are you attempting to target?
.NET 8 Isolated
### Description
TL;DR The in-process model has allowed dependencies to be used without fully wiring up all dependencies. Isolated doesn't allow this.
After migrating from in-process to isolated model, where we've used dependency injection, we've noticed a fairly significant difference in the way dependencies are resolved between the two. We could find nothing explaining this in the migration documentation, and very little else online.
In the in-process model, it appears only direct dependencies of the function class are resolved as required services. All dependencies of those dependencies (and so on) appear to be resolved as optional services (i.e. `_serviceProvider.GetService()`), so the injected sub-dependencies may currently be NULL in an existing in-process functions dependency.
After switching to an isolated model, these sub-dependencies are all resolved as required services (as with standard .NET DI, unless they are optional parameters), and an exception will now be thrown on construction/trigger if the required interface/type is not registered.
For larger legacy codebases, it's possible in-process functions may have been working perfectly fine without being wired up fully, by just avoiding calling code that used the dependencies, but would now fail to run at all in isolated model.
Although this is fairly easy to fix, by registering all the dependencies (or refactoring/splitting service types), it's may be a slow process of hitting single exceptions until everything is wired up fully. It would be good to have this mentioned in the migration documentation, so it's known upfront before going through a migration and then finding function don't run.
### Project configuration and dependencies
_No response_
### Link to a repository that reproduces the issue
_No response_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the existing migration documentation for .NET 6 in-process to .NET 8 isolated projects and review its dependency-injection guidance. Document the difference in required dependency resolution and explain that migrated applications may need all transitive services registered; done means the migration documentation warns readers about this failure mode.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100