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