Refactor backdoor handling and configuration loading
- Changed `TryGet` method return type from `bool?` to `bool` in `BackdoorExtensions.cs` for improved clarity.
- Updated configuration retrieval in `DependencyInjection.cs` to use `GetSection("backdoors")` for targeted loading.
- Added `backdoors.json` configuration file in `Program.cs` to enhance modularity and organization of settings.
This commit is contained in:
parent
74c229bc2d
commit
addba9cdfa
@ -4,7 +4,7 @@ public static class BackdoorExtensions
|
||||
{
|
||||
public static Backdoor? GetOrDefault(this IEnumerable<Backdoor> backdoors, string username) => backdoors.Where(b => b.Username == username).FirstOrDefault();
|
||||
|
||||
public static bool? TryGet(this IEnumerable<Backdoor> backdoors, string username, out Backdoor backdoor)
|
||||
public static bool TryGet(this IEnumerable<Backdoor> backdoors, string username, out Backdoor backdoor)
|
||||
{
|
||||
var _backdoor = backdoors.Where(b => b.Username == username).FirstOrDefault() ?? default;
|
||||
#pragma warning disable CS8601
|
||||
|
||||
@ -6,7 +6,7 @@ public static class DependencyInjection
|
||||
{
|
||||
public static IServiceCollection AddBackdoors(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var backdoors = configuration.Get<IEnumerable<Backdoor>>() ?? Enumerable.Empty<Backdoor>();
|
||||
var backdoors = configuration.GetSection("backdoors").Get<IEnumerable<Backdoor>>() ?? Enumerable.Empty<Backdoor>();
|
||||
return services.AddSingleton(Options.Create(backdoors));
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,6 +27,8 @@ try
|
||||
|
||||
builder.Configuration.AddJsonFile("consumer-repository.json", true, true);
|
||||
|
||||
builder.Configuration.AddJsonFile("backdoors.json", true, true);
|
||||
|
||||
var config = builder.Configuration;
|
||||
|
||||
var apiParams = config.Get<AuthApiParams>() ?? throw new InvalidOperationException("AuthApiOptions is missing or invalid in appsettings.");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user