The .NET provided DI container has some means to check if the container can be created. This is useful to ensure that all dependencies can be resolved and that the container is correctly configured. Let's have a quick look.
Verify that the container can be created
Let's start with the simple code:
builder.Host.UseDefaultServiceProvider((_, options) =>
{
options.ValidateScopes = true;
options.ValidateOnBuild = true;
});
This code will enable the validation of scopes and the validation of the container when it is built. If not configured properly, the container will throw an exception. This will be done, by default, if the current environment is Development
(as mentioned by @kapsiR - this is due to performance reasons). So if you use different environment names, you might want to enable that check for your environment.
As a matter of fact, I like to keep that setting enabled over all environments, as it helps to catch issues early on. You know, fail fast.