---
title: "Validate that your DI Container can be created in ASP.NET Core"
description: "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."
updated: 2025-02-03
tags: [".NET", "C#", "DI", "ASP.NET"]
canonical: "https://steven-giesel.com/blogPost/d67df2e6-b8f7-4fd8-92ba-426e268b5216/validate-that-your-di-container-can-be-created-in-aspnet-core"
---

# Validate that your DI Container can be created in ASP.NET Core

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:
```csharp
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](https://github.com/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**.