I'm not entirely clear on exactly what your question is... But I interpret it as "How do I configure a project to use a specific implementation of an interface inside my AppHost?"
To do that, you would pass down a configuration that tells your app which implementation of an interface to use and then let that project choose the implementation based on the passed down configuration. This is probably most easily done through arguments, but can also be done with environment variables.
In your Apphost class, using arguments:
// Add your project to the IDistributedApplicationBuilder
builder.AddProject<Projects.MyWebUI>("my-web-ui").WithArgs("MyMagicA");
And then inside the MyWebUi.Program.cs file:
if (args.Contains("MyMagicA"))
{
builder.Services.AddScoped<IMyMagic, MyMagicA>();
}
// Handle the case where we are told to use MyMagicB
else if (args.Contains("MyMagicB"))
{
builder.Services.AddScoped<IMyMagic, MyMagicB>();
}
// Probably have some fallback value if no matching argument was passed in,
// or throw exception.
AppHost, using environment variables:
// Environment variable is added as a key-value pair
builder.AddProject<Projects.MyWebUI>("my-web-ui").WithEnvironment("magic-key", "MyMagicA");
MyWebUi.Program.cs file:
// Get the value from environment variables using the key:
var magicKey = builder.Configuration["magic-key"];
if (magicKey == "MyMagicA")
{
builder.Services.AddScoped<IMyMagic, MyMagicA>();
}
// Handle the case where we are told to use MyMagicB
else if (magicKey == "MyMagicB")
{
builder.Services.AddScoped<IMyMagic, MyMagicB>();
}