-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
104 lines (85 loc) · 3.3 KB
/
Copy pathProgram.cs
File metadata and controls
104 lines (85 loc) · 3.3 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
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.EntityFrameworkCore;
using Npgsql;
using Quartz;
using Quartz.Impl;
using Quartz.Spi;
using TenderFlow.AI.Embedding;
using TenderFlow.AI.Orchestration;
using TenderFlow.AI.Providers;
using TenderFlow.AI.Rag;
using TenderFlow.Data;
using TenderFlow.Helpers;
using TenderFlow.Jobs;
using TenderFlow.Services;
using QuartzHostedService = TenderFlow.Services.QuartzHostedService;
var builder = WebApplication.CreateBuilder(args);
NpgsqlConnection.GlobalTypeMapper.UseVector();
//Swagger
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Add services to the container.
builder.Services.AddControllersWithViews().AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
options.JsonSerializerOptions.PropertyNamingPolicy = null;
});
builder.Services.AddDbContext<TenderFlowContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.Cookie.Name = "TenderFlowAuthentication";
options.CookieManager = new ChunkingCookieManager();
options.Cookie.HttpOnly = true;
options.Cookie.SameSite = SameSiteMode.Lax;
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
options.LoginPath = "/Identity/Login";
options.LogoutPath = "/Identity/Logout";
options.AccessDeniedPath = "/Home/AccessDenied";
options.ExpireTimeSpan = TimeSpan.FromDays(30);
options.SlidingExpiration = true;
options.Cookie.MaxAge = options.ExpireTimeSpan;
});
builder.Services.AddAuthorization();
builder.Services.AddHttpClient("Gemini");
builder.Services.AddHttpClient("OpenAI");
builder.Services.AddScoped<IRagService, RagService>();
builder.Services.AddScoped<PgVectorRagService>();
builder.Services.AddScoped<IAiEmbeddingProvider, GeminiEmbeddingProvider>();
builder.Services.AddScoped<IAiEmbeddingProvider, OpenAiEmbeddingProvider>();
builder.Services.AddScoped<IEmbeddingSelector, EmbeddingSelector>();
builder.Services.AddScoped<IAiProvider, OpenAiProvider>();
builder.Services.AddScoped<IAiProvider, GeminiProvider>();
builder.Services.AddScoped<IAiOrchestrator, AiOrchestrator>();
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<ShipmentJob>();
builder.Services.AddSingleton<IJobFactory, QuartzJobFactory>();
builder.Services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
builder.Services.AddHostedService<QuartzHostedService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
// Swagger middleware
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "TENDER FLOW API v1");
c.RoutePrefix = "swagger"; // URL -> /swagger
});
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapStaticAssets();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}")
.WithStaticAssets();
app.MapControllers();
app.Run();