| | 1 | | namespace Syki.Back.Settings; |
| | 2 | |
|
| | 3 | | public class FeaturesSettings |
| | 4 | | { |
| | 5 | | public bool SkipUserRegister { get; set; } |
| | 6 | | public bool CrossLogin { get; set; } |
| | 7 | |
|
| | 8 | | public FeaturesSettings() {} |
| | 9 | |
|
| | 10 | | public FeaturesSettings(IConfiguration configuration) |
| | 11 | | { |
| | 12 | | configuration.GetSection("Features").Bind(this); |
| | 13 | | } |
| | 14 | | } |
| | 15 | |
|
| 1 | 16 | | public class LoadFeatureFlagsFromDb(IServiceScopeFactory serviceScopeFactory, FeaturesSettings settings) : IHostedServic |
| | 17 | | { |
| | 18 | | public async Task StartAsync(CancellationToken cancellationToken) |
| | 19 | | { |
| 2 | 20 | | if (Env.IsTesting()) return; |
| | 21 | |
|
| 0 | 22 | | using IServiceScope scope = serviceScopeFactory.CreateScope(); |
| 0 | 23 | | var ctx = scope.ServiceProvider.GetRequiredService<SykiDbContext>(); |
| | 24 | |
|
| 0 | 25 | | var features = await ctx.FeatureFlags.AsNoTracking() |
| 0 | 26 | | .Where(f => f.Id == Guid.Empty) |
| 0 | 27 | | .FirstOrDefaultAsync(cancellationToken); |
| | 28 | |
|
| 0 | 29 | | if (features == null) return; |
| | 30 | |
|
| 0 | 31 | | settings.SkipUserRegister = features.Settings.SkipUserRegister; |
| 0 | 32 | | settings.CrossLogin = features.Settings.CrossLogin; |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | public Task StopAsync(CancellationToken cancellationToken) |
| | 36 | | { |
| 1 | 37 | | return Task.CompletedTask; |
| | 38 | | } |
| | 39 | | } |