-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
152 lines (129 loc) · 6.01 KB
/
Copy pathProgram.cs
File metadata and controls
152 lines (129 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using BloodLink.Components;
using BloodLink.IDAL;
using BloodLink.DAL;
using BloodLink.Services;
using BloodLink.Models.Auth;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using System.Text;
using Microsoft.AspNetCore.Components.Server;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var razorBuilder = builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
// Enable detailed errors for Blazor Server circuits (development only)
if (builder.Environment.IsDevelopment())
{
builder.Services.Configure<Microsoft.AspNetCore.Components.Server.CircuitOptions>(options =>
{
options.DetailedErrors = true;
});
}
// =====================================================
// DATABASE CONNECTION CONFIGURATION
// =====================================================
builder.Services.AddSingleton<IConfiguration>(builder.Configuration);
// =====================================================
// DATA ACCESS LAYER (DAL) REGISTRATION
// =====================================================
// Base DAL
builder.Services.AddScoped<IBaseDAL, BaseDAL>();
// Entity-specific DALs
builder.Services.AddScoped<IUserDAL, UserDAL>();
builder.Services.AddScoped<IDonorDAL, DonorDAL>();
builder.Services.AddScoped<IRecipientDAL, RecipientDAL>();
builder.Services.AddScoped<IBloodBankDAL, BloodBankDAL>();
builder.Services.AddScoped<IBloodRequestDAL, BloodRequestDAL>();
builder.Services.AddScoped<IRequestMatchDAL, RequestMatchDAL>();
builder.Services.AddScoped<IAppointmentDAL, AppointmentDAL>();
builder.Services.AddScoped<IDonationDAL, DonationDAL>();
builder.Services.AddScoped<IDonorAvailabilityDAL, DonorAvailabilityDAL>();
builder.Services.AddScoped<INotificationDAL, NotificationDAL>();
builder.Services.AddScoped<IReviewDAL, ReviewDAL>();
builder.Services.AddScoped<IChatMessageDAL, ChatMessageDAL>();
builder.Services.AddScoped<ISystemAnalyticsDAL, SystemAnalyticsDAL>();
builder.Services.AddScoped<IBloodInventoryDAL, BloodInventoryDAL>();
// =====================================================
// BUSINESS LOGIC SERVICES REGISTRATION
// =====================================================
// Core Services
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IDonorService, DonorService>();
builder.Services.AddScoped<IRecipientService, RecipientService>();
builder.Services.AddScoped<IBloodBankService, BloodBankService>();
builder.Services.AddScoped<IBloodRequestService, BloodRequestService>();
builder.Services.AddScoped<IAppointmentService, AppointmentService>();
builder.Services.AddScoped<IDonationService, DonationService>();
builder.Services.AddScoped<IReviewService, ReviewService>();
builder.Services.AddScoped<INotificationService, NotificationService>();
builder.Services.AddScoped<IChatMessageService, ChatMessageService>();
builder.Services.AddScoped<ISystemAnalyticsService, SystemAnalyticsService>();
builder.Services.AddScoped<IBloodInventoryService, BloodInventoryService>();
builder.Services.AddScoped<IEmailService, EmailService>();
builder.Services.AddScoped<IFileStorageService, FileStorageService>();
// Service Test Helper (for development/testing)
builder.Services.AddScoped<ServiceTestHelper>();
// =====================================================
// AUTHENTICATION SERVICES REGISTRATION
// =====================================================
// JWT Configuration
builder.Services.Configure<JwtSettings>(builder.Configuration.GetSection("JwtSettings"));
// Authentication Services
builder.Services.AddScoped<IJwtService, JwtService>();
builder.Services.AddScoped<IAuthService, AuthService>();
builder.Services.AddSingleton<UserSessionService>();
builder.Services.AddScoped<AuthStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(provider => provider.GetRequiredService<AuthStateProvider>());
// =====================================================
// ADDITIONAL CONFIGURATION
// =====================================================
// Add logging
builder.Services.AddLogging();
// Add memory cache for better performance
builder.Services.AddMemoryCache();
// Add HTTP context accessor for accessing current user
builder.Services.AddHttpContextAccessor();
// =====================================================
// AUTHENTICATION & AUTHORIZATION (FIXED: Proper JWT configuration)
// =====================================================
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = builder.Configuration["JwtSettings:Issuer"],
ValidAudience = builder.Configuration["JwtSettings:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(builder.Configuration["JwtSettings:SecretKey"] ?? ""))
};
});
builder.Services.AddAuthorization();
// =====================================================
// FUTURE ENHANCEMENTS (COMMENTED OUT)
// =====================================================
// Uncomment these when implementing API controllers
// builder.Services.AddControllers();
// Uncomment these when implementing SignalR for real-time notifications
// builder.Services.AddSignalR();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
// Add authentication and authorization middleware
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();