Add Parameter support to common methods, such as AddDatabase
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
It can be complex to pass in/ read configuration parameters for items such as database names or blob/ container names.
This is especially useful for multi-environment deployments and integration tests (example later).
### Describe the solution you'd like
Something like this:
```csharp
// --- Program.cs
builder.Services.AddOptionsWithValidateOnStart(AppHostOptions.SectionName);
// Configuration based....
var d = builder.AddParameterFromConfiguration(
"database-name",
AppHostOptions.SectionName + ":" + nameof(AppHostOptions.DatabaseName)
);
// Or an even nicer fluent option...
var d = builder.AddParameterFromConfiguration(
"database-name",
options => options.DatabaseName
);
...
// Use the parameter later...
var db = sql.AddDatabase("eventstore-sqlserver", d);
// --- AppHostOptions.cs
sealed class AppHostOptions
{
public const string SectionName = "AppHost:EventStore";
public string DatabaseName { get; set; } = "EventStoreDb";
... etc
}
```
### Additional context
This can be used to isolate test runs for parallal execution when the Sql Server integration is persistent. Here's a partial example using the (excellent) [`TUnit.Aspire`](https://www.nuget.org/packages/TUnit.Aspire) package...
```csharp
public sealed class AppHostFixture : AspireFixture
{
readonly string _databaseName = $"EventStoreDbTest_" + $"{Guid.NewGuid():N}"[..8];
protected override string[] Args => [$"AppHost:EventStore:DatabaseName={_databaseName}"];
...
}
```
Contributor guide
Assessment
This issue has not been assessed yet.