-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
40 lines (26 loc) · 1.15 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
using PgNotifyNet;
using PgNotifyNet.Extensions;
using PgNotifyNet.Interfaces;
using PgNotifyNet.Sample.Hubs;
using PgNotifyNet.Sample.Models;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddPgNotifyNet(builder.Configuration.GetConnectionString("SampleDatabase"),
c => c.Trigger(t => t.OnTable<Category>(table: "categories", schema: "public").After(Change.Update, Change.Insert, Change.Delete))
.Trigger(t => t.OnTable<Test>(table:"testtable",schema:"test").After(Change.Update))
);
builder.Services.AddSignalR();
var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapHub<DbNotificationHub>("/dbNotifications");
app.MapFallbackToPage("/_Host");
var notificationService = app.Services.GetRequiredService<IPgNotificationService>();
notificationService.OnDataChange += NotificationService_OnDataChange;
app.Run();
static void NotificationService_OnDataChange(object? sender, OnDataChangeEventArgs e)
{
Console.WriteLine($"{e.Table} {e.Action} triggered");
}