-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStartup.cs
More file actions
49 lines (42 loc) · 1.4 KB
/
Startup.cs
File metadata and controls
49 lines (42 loc) · 1.4 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
#pragma warning disable CA1822
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
#region Startup
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
var configuration = new PassthroughConfiguration(
connectionFunc: OpenConnection,
callback: Callback,
dedupCriticalError: exception =>
{
Environment.FailFast("Dedup cleanup failure", exception);
});
services.AddSqlHttpPassthrough(configuration);
services.AddMvcCore();
// other ASP.MVC config
}
static Task<Table> Callback(HttpContext http, PassthroughMessage message)
{
//TODO: validate that the message type is allowed
//TODO: validate that the destination is allowed
if (message.Destination == null)
{
var customDestination = new Table("Custom");
return Task.FromResult(customDestination);
}
var destination = new Table(message.Destination);
return Task.FromResult(destination);
}
public void Configure(IApplicationBuilder builder)
{
builder.AddSqlHttpPassthroughBadRequestMiddleware();
builder.UseMvc();
// other ASP.MVC config
}
static Task<SqlConnection> OpenConnection(Cancel cancel) =>
//TODO open and return a SqlConnection
null!;
}
#endregion