Closed verdysh closed 3 years ago
It's a feature; when you run the project from VS, it sets the ASPNETCORE_ENVIRONMENT variable to Development. (Check your launchSettings.json file) And if the environment is Development, it validates the scopes of the services.
It's a feature; when you run the project from VS, it sets the ASPNETCORE_ENVIRONMENT variable to Development. (Check your launchSettings.json file) And if the environment is Development, it validates the scopes of the services.
Thanks for the answer! It seems, this validation should prevent incorrect resources utilization. If it's true, why this validation is turn off for production environment, where resources utilization usually are more important then in development environment?
Not 100% sure about this, but I think there is a performance impact when you validate the scopes when dependencies are resolved. So that is probably why it is skipped by default in the production environment. Also, since you would have tested the application in development before pushing it to production, you would catch the issue.
Not 100% sure about this, but I think there is a performance impact when you validate the scopes when dependencies are resolved. So that is probably why it is skipped by default in the production environment. Also, since you would have tested the application in development before pushing it to production, you would catch the issue.
Again thanks for the answer!
@Vake93 is correct, it's the performance impact.
@Vake93 is correct, it's the performance impact.
Thanks for confirming. I was pretty sure it was but didn't find docs on design reasons behind that choice. So I didn't confirm.
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.
See our Issue Management Policies for more information.
Hi!
Environment: Windows 10 Visual studio 2019 Version 16.10.3 Asp.NET core 3.1
I have simple asp.net core app which launched with Kestrel. I am experimenting with HttpClientFactory and have caught an interesting behaviour. I have 2 services. First:
Second:
I have registered them inside ConfigureServices:
And in Configure(...) method I am tryin call my Service1:
If I start this code in Visual Studio (doesn't matter in Debug or Release mode), exception is throwing: System.InvalidOperationException: 'Cannot resolve scoped service 'WebApplication1.IService2' from root provider.'
If I start application with double click on exe file, application successfully starts. Difference was in "ASPNETCORE_ENVIRONMENT" variable. As I removed it from Visual Studio debug settings, the app was started successfully in Visual Studio as well.
Is this behaviour a bug or a feature?
Thank in advance!