Repository navigation
Expand file tree
/
Copy pathIndexedDbProviderRegistration.cs
More file actions
67 lines (52 loc) · 1.82 KB
/
Copy pathIndexedDbProviderRegistration.cs
File metadata and controls
67 lines (52 loc) · 1.82 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
using System.Runtime.CompilerServices;
using Microsoft.JSInterop;
using OutWit.Database.Core.Interfaces;
using OutWit.Database.Core.Providers;
namespace OutWit.Database.Core.IndexedDb;
/// <summary>
/// Registers IndexedDB providers with the ProviderRegistry.
/// Called automatically via ModuleInitializer when the assembly is loaded.
/// </summary>
public static class IndexedDbProviderRegistration
{
#region Fields
private static bool s_initialized;
private static readonly Lock s_lock = new();
#endregion
#region Initialize
/// <summary>
/// Registers IndexedDB providers. Safe to call multiple times.
/// Called automatically via ModuleInitializer, but can be called explicitly
/// to ensure registration before using providers.
/// </summary>
[ModuleInitializer]
public static void Initialize()
{
if (s_initialized) return;
lock (s_lock)
{
if (s_initialized) return;
RegisterStorageProviders();
s_initialized = true;
}
}
/// <summary>
/// Ensures IndexedDB providers are registered.
/// Alias for Initialize() for more explicit API.
/// </summary>
public static void EnsureRegistered() => Initialize();
#endregion
#region Registration
private static void RegisterStorageProviders()
{
// Register IndexedDB storage provider
ProviderRegistry.Instance.RegisterOrReplace<IStorage>(StorageIndexedDb.PROVIDER_KEY, p =>
{
var databaseName = p.GetRequired<string>("databaseName");
var jsRuntime = p.GetRequired<IJSRuntime>("jsRuntime");
var pageSize = p.Get("pageSize", DatabaseConstants.DEFAULT_PAGE_SIZE);
return new StorageIndexedDb(databaseName, jsRuntime, pageSize);
});
}
#endregion
}