ASP.NET Core 依赖注入中的Scope

每个请求是一个Scope

为什么不能直接从Root Scope中Resolve实例,会造成内存泄漏,原因是Root Scope不会Dispose,长命持有短命问题

注意CreateScope() Scope的范围

Ref

https://andrewlock.net/the-dangers-and-gotchas-of-using-scoped-services-when-configuring-options-in-asp-net-core/
https://blog.ploeh.dk/2014/06/02/captive-dependency/

posted @ 2024-04-11 12:04  talentzemin  阅读(26)  评论(0编辑  收藏  举报