Skip to content

Commit

Permalink
Don't nullcheck the config.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTedder committed Oct 13, 2023
1 parent a6903eb commit e5152e0
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions LeaderboardBackend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,31 @@
.ValidateDataAnnotationsRecursively()
.ValidateOnStart();

ApplicationContextConfig? appContextConfig = builder.Configuration.GetSection(ApplicationContextConfig.KEY).Get<ApplicationContextConfig>();
PostgresConfig db = builder.Configuration.GetSection(ApplicationContextConfig.KEY).Get<ApplicationContextConfig>()!.Pg!;

if (appContextConfig is not null && appContextConfig.Pg is not null)
NpgsqlConnectionStringBuilder connectionBuilder = new()
{
PostgresConfig db = appContextConfig.Pg;
NpgsqlConnectionStringBuilder connectionBuilder = new()
{
Host = db.Host,
Username = db.User,
Password = db.Password,
Database = db.Db,
IncludeErrorDetail = true,
};

if (db.Port is not null)
{
connectionBuilder.Port = db.Port.Value;
}
Host = db.Host,
Username = db.User,
Password = db.Password,
Database = db.Db,
IncludeErrorDetail = true,
};

if (db.Port is not null)
{
connectionBuilder.Port = db.Port.Value;
}

NpgsqlDataSourceBuilder dataSourceBuilder = new(connectionBuilder.ConnectionString);
dataSourceBuilder.UseNodaTime().MapEnum<UserRole>();
NpgsqlDataSource dataSource = dataSourceBuilder.Build();
NpgsqlDataSourceBuilder dataSourceBuilder = new(connectionBuilder.ConnectionString);
dataSourceBuilder.UseNodaTime().MapEnum<UserRole>();
NpgsqlDataSource dataSource = dataSourceBuilder.Build();

builder.Services.AddDbContext<ApplicationContext>(opt =>
{
opt.UseNpgsql(dataSource, o => o.UseNodaTime());
opt.UseSnakeCaseNamingConvention();
});
}
builder.Services.AddDbContext<ApplicationContext>(opt =>
{
opt.UseNpgsql(dataSource, o => o.UseNodaTime());
opt.UseSnakeCaseNamingConvention();
});

// Add services to the container.
builder.Services.AddScoped<IUserService, UserService>();
Expand Down

0 comments on commit e5152e0

Please sign in to comment.