44 lines
2.1 KiB
C#
44 lines
2.1 KiB
C#
using Blazored.LocalStorage;
|
|
using HealthcareManagerUiWebAssem;
|
|
using HealthcareManagerUiWebAssem.Services.AdminUserManagement;
|
|
using HealthcareManagerUiWebAssem.Services.Authentication;
|
|
using HealthcareManagerUiWebAssem.Services.DoctorManagement;
|
|
using HealthcareManagerUiWebAssem.Services.PatientManagement;
|
|
using HealthcareManagerUiWebAssem.Services.RequestHttp;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
|
|
|
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(); |