public OcelotConfigDbDal(OcelotConfigDbConfiguration configDbConfiguration) { this.DbConnectionString = configDbConfiguration.ConnectionString; OcelotConfigTableName = configDbConfiguration.ConfigTableName; Sql_QueryAllConfig = $"SELECT [Id],[Section],[Payload],[CreateTime],[LastUpdate] FROM [dbo].[{OcelotConfigTableName}]"; Sql_QueryBySection = $"SELECT * FROM [dbo].[{OcelotConfigTableName}] Where Section=@Section;"; Sql_Insert = $"INSERT INTO[dbo].[{OcelotConfigTableName}]([Section],[Payload],[CreateTime],[LastUpdate])VALUES(@Section, @Payload, @CreateTime, @LastUpdate)"; Sql_Update = $"UPDATE[dbo].[{OcelotConfigTableName}] SET [Section] = @Section,[Payload] = @Payload,[LastUpdate] = @LastUpdate WHERE Id=@Id"; }
public static IOcelotBuilder AddConfigStoredInSQLServer(this IOcelotBuilder builder, Action <OcelotConfigDbConfiguration> ocelotCfgDbOptions = null) { var options = new OcelotConfigDbConfiguration(); builder.Services.AddSingleton(options); ocelotCfgDbOptions?.Invoke(options); builder.Services.AddSingleton(SqlServerMiddlewareConfigurationProvider.Get); builder.Services.AddSingleton <IFileConfigurationRepository, SqlServerFileConfigurationRepository>(); builder.Services.AddSingleton <IOcelotCache <FileConfiguration>, OcelotConfigCache>(); builder.Services.AddSingleton(typeof(OcelotConfigDbDal), new OcelotConfigDbDal(options)); builder.Services.Remove(new ServiceDescriptor(typeof(IFileConfigurationRepository), typeof(DiskFileConfigurationRepository))); builder.Services.Remove(new ServiceDescriptor(typeof(IOcelotCache <FileConfiguration>), typeof(InMemoryCache <FileConfiguration>))); return(builder); }