When using DI in Controller shall I ca...
When using DI in Controller shall I ca...
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.Manual Disposal:
using
statement or explicitly callin...senior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào