When using DI in Controller shall I call IDisposable on any injected service?
When using DI in Controller shall I call IDisposable on any injected service?
When using Dependency Injection (DI) in an ASP.NET Core Controller, you generally should not call IDisposable on any injected service manually. The DI container in ASP.NET Core is responsible for managing the lifecycle of the services it creates, including disposing of them when appropriate.
Here are the key points to consider:
Service Lifetimes:
Automatic Disposal:
Dispose on IDisposable services it creates when their lifetime ends. For example, scoped services are disposed of at the end of the request, and singleton services are disposed of when the application shuts down.Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.