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
|
|
|
|
|
|
|
|
services.AddTransient<HttpLoggingHandler>();
|
|
|
|
|
|
|
|
|
|
services.AddHttpClient<AuthService>(client =>
|
|
|
|
|
{
|
|
|
|
|
client.BaseAddress = new Uri(baseUri);
|
|
|
|
|
})
|
|
|
|
|
.AddHttpMessageHandler<HttpLoggingHandler>();
|
|
|
|
|
|
|
|
|
|
services.AddHttpClient<LayerService>(client =>
|
|
|
|
|
{
|
|
|
|
|
client.BaseAddress = new Uri(baseUri);
|
|
|
|
|
})
|
|
|
|
|
.AddHttpMessageHandler<HttpLoggingHandler>();
|
2025-11-19 16:57:42 +01:00
|
|
|
|
2025-11-06 10:20:00 +01:00
|
|
|
// Services
|
|
|
|
|
services.AddScoped<AuthService>();
|
|
|
|
|
services.AddScoped<LayerService>();
|
2025-11-19 16:57:42 +01:00
|
|
|
|
2025-11-06 10:20:00 +01:00
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
}
|