Code: Select all
var mysql = builder.AddMySql("db")
.WithEndpoint(port: 3306, targetPort: 3306, name: "mySqlPort")
.WithLifetime(ContainerLifetime.Persistent)
.WithInitBindMount("../sql/", true)
.WithDataVolume();
< /code>
builder.AddProject
("graphql")
.WaitFor(mysql)
.WithEnvironment("ConnectionStrings__FooContext",
"Server=db;Database=Foo;User=root;Password=aVerysecretPasswordIndeed;");
< /code>
And the GraphQL's section:
var builder = WebApplication.CreateSlimBuilder(args);
builder.AddServiceDefaults();
builder.Services.AddKeyedSingleton(DependencyInjectionKeys.FooContextOptionsBuilderKey, (sp, _) =>
{
var connectionString = builder.Configuration.GetConnectionString(nameof(FooContext));
if (string.IsNullOrEmpty(connectionString))
{
//omitted; get it from somewhere else
connectionString = $"server={dbHost};port={dbPort};database={dbName};user={dbUser};password={dbPassword};";
}
// fails here,
// Unable to connect to any of the specified MySQL hosts
var serverVersion = ServerVersion.AutoDetect(connectionString);
return (options) =>
{
options.UseMySql(connectionString, serverVersion, o => o.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery))
.ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))
.EnableSensitiveDataLogging(false)
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTrackingWithIdentityResolution);
};
});
< /code>
I've verified, that connectionString