2026-02-24 20:44:16 +00:00
|
|
|
|
using System;
|
2026-06-19 08:49:49 +00:00
|
|
|
|
using System.Linq;
|
2026-02-24 20:44:16 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Sozsoft.Platform.Entities;
|
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2026-06-19 08:49:49 +00:00
|
|
|
|
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;
|
2026-06-19 08:49:49 +00:00
|
|
|
|
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>();
|
|
|
|
|
|
context.ApplicationConfiguration.SetProperty("version", configuration.GetValue<string>("App:Version"));
|
|
|
|
|
|
|
2026-08-09 08:52:28 +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>>();
|
2026-08-09 08:52:28 +00:00
|
|
|
|
context.ApplicationConfiguration.SetProperty("routes", await routeRepository.GetListAsync());
|
2026-02-24 20:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
var customComponentRepository = context.ServiceProvider.GetRequiredService<IRepository<CustomComponent, Guid>>();
|
2026-08-09 08:52:28 +00:00
|
|
|
|
context.ApplicationConfiguration.SetProperty(
|
|
|
|
|
|
"customComponents", await customComponentRepository.GetListAsync());
|
2026-06-19 08:49:49 +00:00
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|