-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
60 lines (44 loc) · 1.59 KB
/
Program.cs
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
using BusTicketSystem.Models;
using BusTicketSystem.Data;
using BusTicketSystem.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using BusTicketSystem.Data.Identity;
using BusTicketSystem.Data.Extensions;
var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("TicketSystem");
// Add auth and identity services
builder.Services.AddAuthorization();
builder.Services.AddAuthentication().AddCookie(IdentityConstants.ApplicationScheme)
.AddBearerToken(IdentityConstants.BearerScheme);
builder.Services.AddIdentityCore<User>()
.AddEntityFrameworkStores<UserDbContext>()
.AddApiEndpoints();
// Add database services
builder.Services.AddDbContext<UserDbContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("Users")));
builder.Services.AddDbContext<TicketSystemContext>(options =>
options.UseSqlite(connectionString));
// Adding website services
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Adding custom services
//builder.Services.AddSingleton<GraphService>();
builder.Services.AddScoped<BusService>();
builder.Services.AddScoped<RouteService>();
builder.Services.AddScoped<StopService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.ApplyMigrations();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.CreateDbIfNotExists();
app.MapIdentityApi<User>();
app.Run();