-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathProgram.cs
More file actions
39 lines (30 loc) · 1.36 KB
/
Program.cs
File metadata and controls
39 lines (30 loc) · 1.36 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
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using QueryKit.WebApiTestProject;
using QueryKit.WebApiTestProject.Database;
var builder = WebApplication.CreateBuilder(args);
builder.ConfigureServices();
var app = builder.Build();
app.Run();
public static class WebAppServiceConfiguration
{
public static void ConfigureServices(this WebApplicationBuilder builder)
{
var configuration = builder.Configuration;
var env = builder.Environment;
var services = builder.Services;
services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
var connectionString = configuration.GetConnectionStringOptions().TestingDb;
if(string.IsNullOrWhiteSpace(connectionString))
{
// this makes local migrations easier to manage. feel free to refactor if desired.
connectionString = env.IsDevelopment()
? "Host=localhost;Port=50033;Database=testingdb;Username=postgres;Password=postgres"
: throw new Exception("The database connection string is not set.");
}
services.AddDbContext<TestingDbContext>(options =>
options.UseNpgsql(connectionString,
npgSql => npgSql.MigrationsAssembly(typeof(TestingDbContext).Assembly.FullName))
.UseSnakeCaseNamingConvention());
}
}