Is it a good idea to do the following?
public void Configure(
IApplicationBuilder app,
IWebHostEnvironment env,
IHostApplicationLifetime applicationLifetime)
{
applicationLifetime.ApplicationStarted.Register(() => _container.Verify());
applicationLifetime.ApplicationStopped.Register(() => _container.Dispose());
...
}
I'm wondering if there are edge cases in this pattern that cause verification to be executed too late or too early and if a failed verification leads to an application stop (hopefully it does).
When it comes to calling Dispose
, with the introduction of v4.9 of the Simple Injector ASP.NET Core integration, the Container
is automatically disposed of when the application shuts down. See this documentation section for more information.
If you're using a version lower than v4.9, you might want to consider upgrading. It that's not possible, the use of ApplicationStopped.Register
seems like a good idea.
I can't really comment on the Verify()
behavior, so I'm interested in your experiences with this, although I see no advantage over calling Verify
in the Configure
method.