I am working on an .NET Core Aspire project where I am trying to pass AzureAdB2C configurations from my Aspire application's appsettings.json to an orchestrated application.
How can I successfully pass AzureAdB2C configurations from appsettings.json to my orchestrated application? Is there a best practice to ensure that configurations are correctly transferred between the main application and orchestrated applications? Any help or guidance would be greatly appreciated.
I am using the following approach to configure services and containers:
var builder = DistributedApplication.CreateBuilder(args);
var azureAdB2C = builder.Configuration["AzureAdB2C"];
var redis = builder.AddRedisContainer("redis");
var postgres = builder.AddPostgresContainer("postgres")
.WithAnnotation(new ContainerImageAnnotation
{
Image = "ankane/pgvector",
Tag = "latest",
});
var tenantsDb = postgres.AddDatabase("TenantsDb");
// Services
var tenantsApi = builder.AddProject<Projects.Vexel_Tenants_Api>("vexel.tenants.api")
.WithReference(redis)
.WithReference(tenantsDb)
.WithEnvironment("AzureAdB2C", azureAdB2C);
builder.Build().Run();
However, when trying to access the configurations in the tenant application, I am unable to retrieve the expected values:
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
var test1 = Environment.GetEnvironmentVariable("AzureAdB2C");
var test2 = builder.Configuration.GetSection("AzureAdB2C");
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(options =>
{
builder.Configuration.Bind("AzureAdB2C", options);
},
options => { builder.Configuration.Bind("AzureAdB2C", options); });
Here, test1 is returning null, and the sections of test2 come back empty.
For the moment, I created the following extension method:
And it should be used like this: