Open wangkanai opened 6 months ago
You can add multiple databases just fine, if you want to get a reference to those database then you can't use the fluent API:
var sqlMySql = builder.AddMySql(ResourceConstants.SqlMySql)
.WithEnvironment(DatabaseConstants.MySqlConnection, ResourceConstants.SqlMySql);
var configDb = sqlMySql.AddDatabase(SchemaConstants.Configuration);
var customersDb = sqlMySql.AddDatabase(SchemaConstants.Customers);
var lawyersDb = sqlMySql.AddDatabase(SchemaConstants.Laywers);
Thank you very much, @davidfowl. It took a while to come to your suggestion.
var builder = DistributedApplication.CreateBuilder(args);
var sqlPassword = builder.CreateStablePassword(ResourceConstants.SqlPassword, lower: true, upper: true, numeric: true,
special: true, minLower: 1, minUpper: 1, minNumeric: 1, minSpecial: 1);
var sqlMySql = builder.AddMySql(ResourceConstants.SqlMySql, sqlPassword, 60100)
.WithEnvironment(ResourceConstants.SqlMySql, ResourceConstants.SqlMySql);
var dbConfiguration = sqlMySql.AddDatabase(SchemaConstants.Configuration);
var dbCustomer = sqlMySql.AddDatabase(SchemaConstants.Customer);
Now it works perfectly.
Thank you much David!
Would it be possible for Aspire to actually create the databases in the server?
I noticed that the mssql hosting component allows me to define databases but they are not created.
This means that the connection string passed to the projects can't be used to connect to the database from tools like datagrip or mssql management studio and you need to change the database name to "master".
Also, it would be cool if when inspecting a database resource in the database, we could find the connection string there.
Currently I can only add a single database schema per container.
Preferred solution with multiple database schema per container.