BRAKING refactor project structure.

Refactor: the project is now divided into a more clear structure, with **Infrastructure** and **Application** layers added.

Refactor: configurations are split into sections for different layers.

Fix: now EF Core related operations, such as migration, should be invoked in `OptixServe.Infrastructure`, with config file and data dir passed into `dotnet ef` command. See `OptixServe.Infrastructure/Utilites/DesignTimeDbContextFactory.cs` for details.

Fix: EF migrations are ignored in gitignore on purpose in early development.
This commit is contained in:
2025-07-11 14:48:50 +08:00
parent 47cbdc21c1
commit 8b18de1735
20 changed files with 286 additions and 100 deletions

View File

@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore;
using OptixServe.Infrastructure.Configuration;
namespace OptixServe.Infrastructure.Utilites;
public static class DatabaseHelper
{
public static string BuildConnectionString(DatabaseSettings dbSettings)
{
return dbSettings.Type switch
{
DatabaseType.Sqlite => $"Data Source={dbSettings.Host ?? "optixserve.db"}",
DatabaseType.MySQL => throw new NotSupportedException("MySQL connection is not yet implemented"),
_ => throw new NotSupportedException($"Database type {dbSettings.Type} is not supported")
};
}
public static void ConfigureDbContext(DbContextOptionsBuilder options, DatabaseSettings dbSettings)
{
if (dbSettings?.Type == DatabaseType.Sqlite)
{
var dbPath = dbSettings.Host ?? "optixserve.db";
var connectionString = $"Data Source={dbPath}";
options.UseSqlite(connectionString, b => b.MigrationsAssembly("OptixServe.Infrastructure"));
}
else
{
throw new NotImplementedException("Only SQLite database is currently supported");
}
}
}