-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable Automatically perform verification upon first resolve by default #747
Comments
With the latest changes in the integration packages for ASP.NET Core 3, it became a little more consequential to switch this feature on by default. In ASP.NET Core 3, hosted services can be resolved from Simple Injector by the framework before the The advantage of this is that Middleware can be added to the request pipeline (and registered at that same time), while allowing But here comes the problem. When we enable automatic verification in Simple Injector, it will cause the container to be verified before the The following shows a trimmed down version of the public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddSimpleInjector(container, options =>
{
options.AddAspNetCore().AddControllerActivation();
options.AddHostedService<MyHostedService>();
});
}
// MyHostedService gets resolved before Configure is called
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSimpleInjector(container);
// Default ASP.NET middleware
app.UseStaticFiles();
app.UseRouting();
// UseMiddleware creates a new registration (InstanceProducer)
app.UseMiddleware<CustomMiddleware1>(container);
app.UseEndpoints(...);
// Call verify after UseMiddleware
container.Verify();
} |
Another, and perhaps even more important, issue with this change is when Simple Injector is used inside integration tests. A very common practice is to build a new container instance for each integration test (by reusing the same configuration logic, while perhaps replacing a few test specific dependencies). Configuration the container is reasonably quickly, especially when all assemblies already have been loaded. In that case, however, you would normally not call What this means is that unknowing users might upgrade to v5 and they might even do so without having to make any changes to their source code. But once the upgrade is committed and picketed up by the build server, their integration tests suddenly become very slow. But such delay will usually not be noticed at first, because build servers are typically quite unreliable. So once developers start to notice that the tests now run much more slowly, it will be more difficult to trace what is causing that delay. |
…esolve exception message to become confusing and wrong. Removed that extra information. #747
Still, I find this feature to be very valuable, especially for newer users, but even for experienced users that start a new project. Verify is forgotten to be called more often than not. Over time, developers will start to understand the new behavior, and how to disable auto verification. In the long run having this feature enabled is our best pick. |
The implemented feature of #555 should be enabled by default in v5. Documentation can be found here.
The text was updated successfully, but these errors were encountered: