-
Notifications
You must be signed in to change notification settings - Fork 1
/
InitializeDatabase.cs
39 lines (33 loc) · 1.14 KB
/
InitializeDatabase.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
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.EntityFrameworkCore;
namespace allmylinks;
public static class InitializeDatabase
{
public static void AddDatabaseFeatures(this IServiceCollection services)
{
try {
services.AddDbContextFactory<Context>(
options => options.UseSqlite("Filename=database/main.db"));
}
catch (Exception) {
// ignore
}
services.AddScoped<PersonServices>();
}
public static async Task InitializeDatabaseFeature(this WebAssemblyHost host)
{
try {
// Initialize DatabaseContext and sync with IndexedDb Files
var dbService = host.Services.GetRequiredService<DatabaseService<Context>>();
await dbService.InitDatabaseAsync();
// Sync Contributions
var contributionService = host.Services.GetRequiredService<PersonServices>();
await contributionService.InitAsync();
await host.InitializeDatabaseFeature();
}
catch (Exception) {
// ignore
}
await host.RunAsync();
}
}