2025-11-06 10:20:00 +01:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using DiunaBI.UI.Shared.Services;
|
2025-11-19 17:30:36 +01:00
|
|
|
using DiunaBI.UI.Shared.Handlers;
|
2025-11-06 10:20:00 +01:00
|
|
|
|
|
|
|
|
namespace DiunaBI.UI.Shared.Extensions;
|
|
|
|
|
|
|
|
|
|
public static class ServiceCollectionExtensions
|
|
|
|
|
{
|
|
|
|
|
public static IServiceCollection AddSharedServices(this IServiceCollection services, string apiBaseUrl)
|
|
|
|
|
{
|
2025-11-19 17:30:36 +01:00
|
|
|
// HttpClient for API calls with logging
|
2025-11-19 16:57:42 +01:00
|
|
|
// Ensure BaseAddress ends with / for proper relative URL resolution
|
|
|
|
|
var baseUri = apiBaseUrl.EndsWith('/') ? apiBaseUrl : apiBaseUrl + "/";
|
2025-11-19 17:30:36 +01:00
|
|
|
|
2025-11-19 17:40:27 +01:00
|
|
|
Console.WriteLine($"🔧 Configuring HttpClient with BaseAddress: {baseUri}");
|
|
|
|
|
|
2025-11-19 17:30:36 +01:00
|
|
|
services.AddTransient<HttpLoggingHandler>();
|
|
|
|
|
|
2025-11-19 17:40:27 +01:00
|
|
|
// Configure named HttpClient with logging handler
|
2025-12-01 17:56:17 +01:00
|
|
|
// Note: Authentication is handled by AuthService setting DefaultRequestHeaders.Authorization
|
2025-11-19 17:40:27 +01:00
|
|
|
services.AddHttpClient("DiunaBI", client =>
|
2025-11-19 17:30:36 +01:00
|
|
|
{
|
|
|
|
|
client.BaseAddress = new Uri(baseUri);
|
2025-11-19 17:40:27 +01:00
|
|
|
Console.WriteLine($"✅ HttpClient BaseAddress set to: {client.BaseAddress}");
|
2025-11-19 17:30:36 +01:00
|
|
|
})
|
|
|
|
|
.AddHttpMessageHandler<HttpLoggingHandler>();
|
|
|
|
|
|
2025-11-19 17:40:27 +01:00
|
|
|
// Register a scoped HttpClient factory that services will use
|
|
|
|
|
services.AddScoped<HttpClient>(sp =>
|
2025-11-19 17:30:36 +01:00
|
|
|
{
|
2025-11-19 17:40:27 +01:00
|
|
|
var factory = sp.GetRequiredService<IHttpClientFactory>();
|
|
|
|
|
var client = factory.CreateClient("DiunaBI");
|
|
|
|
|
Console.WriteLine($"🏭 HttpClient created from factory. BaseAddress: {client.BaseAddress}");
|
|
|
|
|
return client;
|
|
|
|
|
});
|
2025-11-19 16:57:42 +01:00
|
|
|
|
2025-11-06 10:20:00 +01:00
|
|
|
// Services
|
|
|
|
|
services.AddScoped<AuthService>();
|
|
|
|
|
services.AddScoped<LayerService>();
|
2025-12-01 12:55:47 +01:00
|
|
|
services.AddScoped<DataInboxService>();
|
2025-12-03 13:33:38 +01:00
|
|
|
services.AddScoped<JobService>();
|
2025-11-19 16:57:42 +01:00
|
|
|
|
2025-12-02 13:23:03 +01:00
|
|
|
// Filter state services (scoped to maintain state during user session)
|
|
|
|
|
services.AddScoped<LayerFilterStateService>();
|
|
|
|
|
services.AddScoped<DataInboxFilterStateService>();
|
|
|
|
|
|
2025-11-06 10:20:00 +01:00
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
}
|