using Microsoft.Extensions.Configuration; var builder = DistributedApplication.CreateBuilder(args); #region Sql Server var sqlConfig = builder.Configuration.GetSection("SqlServer"); ArgumentNullException.ThrowIfNull(sqlConfig); var sqlPassword = builder.AddParameter("prefab-sql-password", secret: true); var sqlContainerName = sqlConfig["ContainerName"]; ArgumentException.ThrowIfNullOrWhiteSpace(sqlContainerName); IResourceBuilder sqlServer; var sqlServerHostPort = sqlConfig["HostPort"]; if (!string.IsNullOrWhiteSpace(sqlServerHostPort) && int.TryParse(sqlServerHostPort, out var hostPort)) { sqlServer = builder.AddSqlServer(sqlContainerName, sqlPassword); sqlServer.WithEndpoint("tcp", e => { e.Port = hostPort; // host port (what clients connect to) e.TargetPort = 1433; // container port (SQL Server listens on 1433) e.IsProxied = false; // disable Aspire's reverse proxy for this endpoint }); } else { sqlServer = builder.AddSqlServer(sqlContainerName, sqlPassword); } var sqlServerDataVolume = sqlConfig.GetValue("UseDataVolume"); if (sqlServerDataVolume.GetValueOrDefault(true)) { sqlServer = sqlServer .WithDataVolume() .WithLifetime(ContainerLifetime.Persistent);; } var database = sqlServer.AddDatabase("prefab-db"); #endregion var catalog = builder.AddProject("prefab-catalog") .WithReference(database) .WithEnvironment("ConnectionStrings__PrefabDb", database.Resource.ConnectionStringExpression) .WithEnvironment("ConnectionStrings__PrefabDbReadOnly", database.Resource.ConnectionStringExpression) .WaitFor(sqlServer); var catalogClientTransport = builder.Configuration["Prefab__Catalog__Client__Transport"] ?? "InProcess"; var catalogClientBaseAddress = builder.Configuration["Prefab__Catalog__Client__BaseAddress"]; var prefabWeb = builder.AddProject("prefab-web") .WithReference(database) .WithEnvironment("ConnectionStrings__PrefabDb", database.Resource.ConnectionStringExpression) .WithEnvironment("ConnectionStrings__PrefabDbReadOnly", database.Resource.ConnectionStringExpression) .WaitFor(sqlServer) .WithReference(catalog) .WaitFor(catalog); prefabWeb.WithEnvironment("Prefab__Catalog__Client__Transport", catalogClientTransport); if (!string.IsNullOrWhiteSpace(catalogClientBaseAddress)) { prefabWeb.WithEnvironment("Prefab__Catalog__Client__BaseAddress", catalogClientBaseAddress); } builder.Build().Run();