-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Describe the issue or suggestion
The docs at https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-guidelines#idisposable-guidance-for-transient-and-shared-instances mention:
Don't register [IDisposable](https://learn.microsoft.com/en-us/dotnet/api/system.idisposable) instances with a transient lifetime. Use the factory pattern instead.
However when Configuring a http service, I can do:
integrationServices.AddHttpClient<MyClient>().AddHttpMessageHandler<MyHandler>()
It says:
If you require access to an app DI scope from your message handler, for authentication as an example, you'd encapsulate scope-aware logic in a separate transient DelegatingHandler
So how should the custom HttpMessageHandlers be registered. As transient? Will this cause memory leak?
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 8d1c8ef1-6a01-df24-34ad-570f88df9303
- Version Independent ID: 7fb2be80-cb54-27bf-4f93-423d8540429e
- Content: Dependency injection guidelines - .NET
- Content Source: docs/core/extensions/dependency-injection-guidelines.md
- Service: dotnet-fundamentals
- GitHub Login: @IEvangelist
- Microsoft Alias: dapine