-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (31 loc) · 1.25 KB
/
Copy pathProgram.cs
File metadata and controls
49 lines (31 loc) · 1.25 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
var builder = WebApplication.CreateBuilder(args);
// 1. Register DbContext (In-Memory)
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseInMemoryDatabase("NotesDb"));
// sql
//builder.Services.AddDbContext<AppDbContext>(options =>
// options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
// 2. Dependency Injection
// Register open generic repository
builder.Services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>));
// Register domain-specific service
builder.Services.AddScoped<INoteService, NoteService>();
// Register MediatR
builder.Services.AddMediatR(cfg =>
cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));
// 3. OpenAPI / Swagger Setup
builder.Services.AddOpenApi(); // Assuming this is an extension method
// 4. Add Auth Middleware Support
builder.Services.AddAuthorization(); // Fixes "AddAuthorization" error
// 5. Build the app
var app = builder.Build();
// 6. Configure Middleware Pipeline
if (app.Environment.IsDevelopment())
{
app.MapOpenApi(); // Assuming this maps Swagger UI & endpoints
}
app.UseHttpsRedirection();
app.UseAuthorization();
// 7. Map Endpoints
app.MapNotesEndpoints(); // Assuming you use Minimal APIs
await app.RunAsync();