Files
FACULTATE-HEALTHCARE_MANAGER/frontend/Program.cs
T
2024-05-21 12:10:53 +03:00

44 lines
2.1 KiB
C#

using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components.Authorization;
using HealthcareManagerUiWebAssem;
using HealthcareManagerUiWebAssem.Services.AdminUserManagement;
using HealthcareManagerUiWebAssem.Services.Authentication;
using HealthcareManagerUiWebAssem.Services.DoctorManagement;
using HealthcareManagerUiWebAssem.Services.PatientManagement;
using HealthcareManagerUiWebAssem.Services.RequestHttp;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
// Configure API settings
var apiSettings = builder.Configuration.GetSection("ApiSettings").Get<ApplicationSettings>();
builder.Services.AddSingleton(apiSettings);
// Configure custom HttpClient handler
builder.Services.AddTransient<AuthenticationHttpMessageHandler>();
builder.Services.AddHttpClient<IRequestHttpService, RequestHttpService>((sp, httpClient) =>
{
var settings = sp.GetRequiredService<ApplicationSettings>();
httpClient.BaseAddress = new Uri(settings.BaseAddress);
}).AddHttpMessageHandler<AuthenticationHttpMessageHandler>();
builder.Services.AddBlazoredLocalStorage();
builder.Services.AddScoped<IAuthenticationService, AuthenticationService>();
builder.Services.AddScoped<IAdminManagementService, AdminManagementService>();
builder.Services.AddScoped<IPatientManagementService, PatientManagementService>();
builder.Services.AddScoped<IDoctorManagementService, DoctorManagementService>();
// Register CustomAuthenticationStateProvider as the AuthenticationStateProvider
builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthenticationStateProvider>();
builder.Services.AddAuthorizationCore(config =>
{
config.AddPolicy("AdminOnly", policy => policy.RequireRole(UserRoles.Admin));
config.AddPolicy("DoctorOnly", policy => policy.RequireRole(UserRoles.Doctor));
config.AddPolicy("PatientOnly", policy => policy.RequireRole(UserRoles.Patient));
});
await builder.Build().RunAsync();