feat: bootstrap local platform development

This commit is contained in:
2026-07-28 17:01:44 +08:00
parent 5732df8886
commit e7d350ec3d
19 changed files with 3230 additions and 7 deletions

View File

@@ -3,12 +3,19 @@ using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Tiku.Infrastructure;
using Tiku.Infrastructure.Persistence;
using Tiku.Infrastructure.Bootstrap;
using Tiku.Application;
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Warning);
var isDevelopment = builder.Environment.IsDevelopment() ||
string.Equals(
Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"),
Environments.Development,
StringComparison.OrdinalIgnoreCase);
var bootstrapPlatformAdmin = args.Contains("--bootstrap-platform-admin", StringComparer.Ordinal);
PlatformAdminBootstrapOptions? bootstrapOptions = null;
if (bootstrapPlatformAdmin)
@@ -22,11 +29,17 @@ if (bootstrapPlatformAdmin)
var connectionString =
builder.Configuration.GetConnectionString("Database") ??
Environment.GetEnvironmentVariable("DATABASE_URL") ??
throw new InvalidOperationException(
"Database connection is required. Configure ConnectionStrings:Database or DATABASE_URL.");
(isDevelopment
? $"Host=localhost;Database=tiku;Username={Environment.UserName}"
: throw new InvalidOperationException(
"Database connection is required outside Development. Configure ConnectionStrings:Database or DATABASE_URL."));
builder.Services.AddApplication();
builder.Services.AddInfrastructure(connectionString);
builder.Services.AddInfrastructure(
connectionString,
isDevelopment && !bootstrapPlatformAdmin
? DevelopmentPlatformAdminSeeder.Configure
: null);
// Resolving UserManager<User> also activates Identity's default token providers.
// Bootstrap never issues a reset token, so the migrator uses a process-local provider;
// the API remains the sole owner of the persisted, certificate-protected key ring.