'Using ValidateOnBuild flag in .net 6.0 with WebApplication.CreateBuilder

I am trying to validate if DI dependencies can be resolved using the ValidateOnBuild flag. So far, I am failing to do so.

I am using a sample application with

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
var app = builder.Build();

Where should I set this flag in order for validation to work?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source