Add: binding setting file items to `AppSettings` class so to provide DI access as `IOptions<OptixServeSettings>`. Add: EF Core and DbContext to access database in services. This results in disabling NativeAOT due to poor supports for *pre-compiled query*, however many design are optimized for AOT for later re-adoption. Add: `DesignTimeDbContextFactory` to support EF Core migrations in NativeAOT. (Kept for re-enabling AOT.) Add: `DbInitializer` for ensuring database connecting in startup. Add: `ConfigurationHelper.CreateDefaultBuilder()` to read configuration files in default locations. Note this method is currently ONLY used by `DesignTimeDbContextFactory`. Refactor is expected. Add: `CommonErrorDto` for simple error message. Add: `VersionEndpoint` ONLY for debugging and testing purpose. Verylikely to be removed in the future. Other: many utilities and fixes easy to understand. Note: EF Core migrations are excluded in the early development. Not expected to be added in version control before v1.0 beta.
35 lines
1018 B
C#
35 lines
1018 B
C#
using System.Text.Json.Serialization;
|
|
using Microsoft.Extensions.Options;
|
|
using OptixServe.Api.Configuration;
|
|
using OptixServe.Api.Dtos;
|
|
|
|
namespace OptixServe.Api.Endpoints;
|
|
|
|
|
|
[JsonSerializable(typeof(string))]
|
|
[JsonSerializable(typeof(CommonErrorDto))]
|
|
public partial class VersionJsonContext : JsonSerializerContext { }
|
|
|
|
|
|
/// <summary>
|
|
/// This is a endpoint ONLY FOR TEST!
|
|
/// Should not expect ANY stable behavior on it!
|
|
/// </summary>
|
|
public static class VersionEndpoint
|
|
{
|
|
public static void Register(RouteGroupBuilder parentGroup)
|
|
{
|
|
var group = parentGroup.MapGroup("/version");
|
|
|
|
group.MapGet("/", () => "v1");
|
|
group.MapGet("/test/dbconfig", (IOptions<OptixServeSettings> appSettings) =>
|
|
{
|
|
var dbType = appSettings.Value.Database?.Type;
|
|
var dbHost = appSettings.Value.Database?.Host;
|
|
return Results.Ok(new CommonErrorDto
|
|
{
|
|
Message = $"Set up {dbType} database on {dbHost}"
|
|
});
|
|
});
|
|
}
|
|
} |