-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (51 loc) · 2.12 KB
/
Copy pathProgram.cs
File metadata and controls
60 lines (51 loc) · 2.12 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
class Program
{
// Back the sample with EfLocalDb: each launch runs against its own LocalDB database, cloned from a
// seeded template. EfLocalDb manages its own instance and self-heals orphaned files, so the sample
// can never wedge on a leftover .mdf the way a fixed-name EnsureCreated database can.
static SqlInstance<SampleContext> sqlInstance = new(
constructInstance: _ => new(_.Options),
buildTemplate: _ =>
{
SampleContext.Initialize(_);
return Task.CompletedTask;
});
static async Task Main(string[] args)
{
var database = await sqlInstance.Build();
var builder = WebApplication.CreateBuilder(args);
// Serve the Blazor client's static web assets even when not running in the Development environment.
builder.WebHost.UseStaticWebAssets();
builder.Services
.AddDbContext<SampleContext>(_ => _.UseSqlServer(database.ConnectionString));
// begin-snippet: serverRegistration
builder.Services
.AddScry<SampleContext>(
_ =>
{
// Holiday is a [QueryablePoco]: it has no table, so the server supplies its rows. Every
// [QueryablePoco] type must be registered here or AddScry throws at startup.
_.AddPocoSource(_ => Holiday.Seed());
_.MaxPageSize = 200;
});
// end-snippet
var app = builder.Build();
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
// begin-snippet: mapScry
app.MapScry("/api/query");
// end-snippet
// begin-snippet: mapExplorer
app.MapScryExplorer(
_ =>
{
_.Route = "/scry";
// This sample always exposes the explorer. The default guard is Development-only — in a real
// app, run in Development or set EnableGuard to your own check (e.g. an admin authorization).
_.EnableGuard = _ => true;
});
// end-snippet
app.MapFallbackToFile("index.html");
await app.RunAsync();
}
}