sozsoft-platform/api/src/Sozsoft.Platform.HttpApi.Host/Extensions/PlatformApplicationConfigurationContributor.cs

73 lines
3.5 KiB
C#
Raw Normal View History

2026-02-24 20:44:16 +00:00
using System;
using System.Linq;
2026-02-24 20:44:16 +00:00
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Sozsoft.Platform.Entities;
using Sozsoft.Platform.Identity;
2026-02-24 20:44:16 +00:00
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
using Volo.Abp.Users;
2026-02-24 20:44:16 +00:00
namespace Sozsoft.Platform.Extensions;
public class PlatformApplicationConfigurationContributor : IApplicationConfigurationContributor, ITransientDependency
{
public async Task ContributeAsync(ApplicationConfigurationContributorContext context)
{
var hostEnvironment = context.ServiceProvider.GetRequiredService<IHostEnvironment>();
context.ApplicationConfiguration.SetProperty("environment", hostEnvironment.EnvironmentName);
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
2026-08-12 21:26:36 +00:00
context.ApplicationConfiguration.SetProperty("apiVersion", configuration.GetValue<string>("App:Version"));
// Uygulamanın çalışan sürümü: istemcinin tek sürüm kaynağı (ayrı bir
// version.json isteği yoktur). Yalnızca EN SON sürüm taşınır; tam liste
2026-08-17 08:51:46 +00:00
// ChangeLog ekranının kendi endpoint'inden (/api/app/change-log) gelir,
2026-08-12 21:26:36 +00:00
// aksi halde her config isteğinde bütün changelog gönderilirdi.
2026-08-17 08:51:46 +00:00
var changeLogRepository = context.ServiceProvider.GetRequiredService<IRepository<ChangeLog, Guid>>();
var changeLogs = await changeLogRepository.GetListAsync(x => x.IsPublished);
2026-08-12 21:26:36 +00:00
2026-08-17 08:51:46 +00:00
var latest = changeLogs
2026-08-12 21:26:36 +00:00
.OrderByDescending(note => note.ReleaseDate)
.ThenByDescending(note => note.Version)
.FirstOrDefault();
context.ApplicationConfiguration.SetProperty("changeLogs", new
{
uiVersion = latest?.Version,
tags = latest?.GetChangeLog() ?? []
});
2026-02-24 20:44:16 +00:00
// GetListAsync boş liste döner, null dönmez — bu yüzden null kontrolü yok.
// Veritabanı erişilemezse çağrı exception atar; bu durum istek boru hattında,
// buraya gelinmeden 503 ile karşılanır (bkz. PlatformHttpApiHostModule).
2026-02-24 20:44:16 +00:00
var routeRepository = context.ServiceProvider.GetRequiredService<IRepository<Route, Guid>>();
context.ApplicationConfiguration.SetProperty("routes", await routeRepository.GetListAsync());
2026-02-24 20:44:16 +00:00
var customComponentRepository = context.ServiceProvider.GetRequiredService<IRepository<CustomComponent, Guid>>();
context.ApplicationConfiguration.SetProperty(
"customComponents", await customComponentRepository.GetListAsync());
var currentUser = context.ServiceProvider.GetRequiredService<ICurrentUser>();
if (currentUser.Id.HasValue)
{
var sessionRepository = context.ServiceProvider.GetRequiredService<IIdentitySessionRepository>();
var sessions = await sessionRepository.GetListAsync(userId: currentUser.Id.Value);
var claimSessionId = currentUser.FindClaim(PlatformClaimTypes.SessionId.Key)?.Value;
var sessionId = sessions.Exists(session => session.SessionId == claimSessionId)
? claimSessionId
: sessions.OrderByDescending(session => session.SignedIn).FirstOrDefault()?.SessionId;
context.ApplicationConfiguration.CurrentUser.SessionId = sessionId;
context.ApplicationConfiguration.SetProperty("currentUserSessionId", sessionId);
}
2026-02-24 20:44:16 +00:00
}
2026-08-12 21:26:36 +00:00
2026-02-24 20:44:16 +00:00
}