-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
87 lines (65 loc) · 2.52 KB
/
Program.cs
File metadata and controls
87 lines (65 loc) · 2.52 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
// Install-Package Microsoft.EntityFrameworkCore
// Install-Package Microsoft.EntityFrameworkCore.Sqlite
// Install-Package Microsoft.EntityFrameworkCore.Tools
// Install-Package Microsoft.SemanticKernel.Connectors.Google -Version 1.67.1-alpha
// Install-Package Microsoft.SemanticKernel.Process.Core -Version 1.67.1-alpha
// Install-Package Microsoft.SemanticKernel.Process.LocalRuntime -Version 1.67.1-alpha
// Install-Package Microsoft.SemanticKernel.Connectors.SqliteVec -prerelease
// https://aistudio.google.com/
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.AI;
using Microsoft.SemanticKernel;
using MyProject.Models;
using MyProject.Processes;
var builder = WebApplication.CreateBuilder(args);
//-- Razor Pages
builder.Services.AddRazorPages();
// HttpContext accessor
builder.Services.AddHttpContextAccessor();
//------ Database service
builder.Services.AddDbContext<ProjectContext>();
//---- Register Auth Services
builder.Services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/Login";
options.AccessDeniedPath = "/Login";
options.ExpireTimeSpan = TimeSpan.FromDays(20);
options.SlidingExpiration = true;
}
);
builder.Services.AddAuthorization();
//--- Register AI Services
// get key here: https://hoven.in/cs-lang/gemini-keys-for-sk.html
builder.Services.AddGoogleAIGeminiChatCompletion(
modelId: "gemini-2.5-flash",
apiKey: ___your__key
);
builder.Services.AddTransient((sp) => new Kernel(sp));
builder.Services.AddTransient((sp) => ProcessBuilderFactory.CreateLoginProcess());
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorPages();
using (var scope = app.Services.CreateScope())
{
// create database directory, if doesn't exist
Directory.CreateDirectory(ProjectContext.DBASE_DIRECTORY);
ProjectContext? ctx = scope.ServiceProvider.GetService<ProjectContext>();
if (true == ctx?.Database.GetPendingMigrations().Any())
{
ctx.Database.Migrate();
app.Logger.LogInformation("Identity migrations applied!");
}
if (true != ctx?.Database.CanConnect())
{
app.Logger.LogError(
@"have you applied migration?
Open package manager console and run these commands first:
Add-Migration Initial_Create -context ProjectContext");
return;
}
}
app.Run();