feat : start login after start program, add appsetings

This commit is contained in:
2025-08-01 16:58:14 +08:00
parent 6a82898765
commit 0dc7e05029
5 changed files with 46 additions and 15 deletions

View File

@@ -1,18 +1,36 @@
using fubon_api.Controllers;
using fubon_api.Models;
using FubonNeo.Sdk;
var builder = WebApplication.CreateBuilder(args);
// appsettings
var fubonSettings = builder.Configuration.GetSection("FubonSettings").Get<FubonSettings>();
if (fubonSettings == null)
{
throw new InvalidOperationException("FubonSettings is missing.");
}
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<FubonSDK>();
builder.Services.AddSingleton<Account>();
builder.Services.AddSingleton<Account>(provider =>
{
var sdk = provider.GetRequiredService<FubonSDK>();
var logger = provider.GetRequiredService<ILogger<Program>>();
var loginResponse = sdk.Login(fubonSettings.Id, fubonSettings.Password, fubonSettings.CertPath, fubonSettings.CertPassword);
if (loginResponse.isSuccess != true || loginResponse.data[0] == null)
{
logger.LogError("Login failed.");
throw new Exception("Login failed.");
}
return loginResponse.data[0];
});
var app = builder.Build();
// Configure the HTTP request pipeline.