'ASP.NET Minimal API - Access IConfiguration

Is it possible to access the the IConfiguration in the new ASP.NET Minimal API? I do not see the possibility to do such thing.

using Microsoft.AspNetCore.Components;
using MudBlazor.Services;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();
...

builder.Services.AddMyServiceWithConfiguration(XXXX.Configuration);

var app = builder.Build();

....

app.Run();


Solution 1:[1]

You can access ConfigurationManager (builder.Configuration) which is an implementation of IConfigurationBuilder, IConfigurationRoot and IConfiguration

After your application is build (builder.Build()), you can access it using app.Services.GetRequiredService<IConfiguration>()

Sources

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

Source: Stack Overflow

Solution Source
Solution 1