What is ServiceProviderOptions.ValidateScopes exactly? I feel I couldn't understand completely what it does under the hood. I've come across this with a tutorial, but no explanation.
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
- How to dynamically load partial view Via jquery aj
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
- Add to htmlAttributes for custom ActionLink helper
I assume you are speaking about this piece of code:
?
The ASP.NET Core Provider has a mechanic which validates if a scoped service is resolved by a singleton container. ASP.NET Core has two kinds of containers. The main, singleton container which is valid for the life-time of the application and scoped containers for every request.
This option will prevent resolving of scoped services from the singleton container, that is if you accidentally try to resolve a scoped service within
Configure
method, you will get an exception. Whereas if you disable it you shouldn't.The exception is something similar to
This behavior is there to prevent memory leaks and resolving scoped services (which are supposed to be short-lived) from singleton container, essentially making this services quasi-singletons too (because they won't get disposed until the container gets disposed and the singleton container only gets disposed when the application is shut down).
The correct way to resolve scoped services within i.e.
Configure
method is thisThe default value is
true
and you should leave it like that unless you know exactly what you are doing otherwise you risk nasty memory leaks (or object already disposed exceptions) by unreleased services.