Enable DI container scope validation by default for Development environment in all ASP.NET Core 2.0 templates
See original GitHub issueUpdate all the ASP.NET Core 2.0 templates to turn on scope validation when in the development environment, e.g.:
public class Startup
{
public Startup(IHostingEnvironment env)
{
HostingEnvironment = env;
}
public IHostingEnvironment HostingEnvironment { get; }
public IServiceProvider ConfigureServices(IServiceCollection services)
{
// Set up container here...
return services.BuildServiceProvider(validateScopes: HostingEnvironment.IsDevelopment());
}
public void Configure()
{
...
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
How do I validate the DI container in ASP.NET Core?
A built-in DI container validation was added in ASP.NET Core 3 and it is enabled only in the Development environment by default.
Read more >Dependency injection in ASP.NET Core
The framework creates a scope per request, and RequestServices exposes the scoped service provider. All scoped services are valid for as long as ......
Read more >New in ASP.NET Core 3: Service provider validation
In this post I describe the new "validate on build" feature that has been added to ASP.NET Core 3.0. This can be used...
Read more >Filters in ASP.NET Core
Learn how filters work and how to use them in ASP.NET Core. ... How filters work; Implementation; Filter scopes and order of execution ......
Read more >ASP.NET Core Web API Best Practices
In this post, we are going to write about what we consider to be the best practices while developing the .NET Core Web...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Scope validation makes sure your dependency graph doesn’t have mismatched lifetimes (like depending on a scoped service from a singleton service). Read about “Captive dependencies” https://blog.ploeh.dk/2014/06/02/captive-dependency/
Simple injector also has a feature to detect this - https://simpleinjector.readthedocs.io/en/latest/LifestyleMismatches.html
We didn’t want the perf hit in production. Since you rarely change registrations at runtime (if ever) you’d catch most things at development time.