Search code examples
servicestackormlite-servicestack

How to retrieve all settings with OrmLiteAppSettings in one call?


I'm using the TextFileSettings and OrmLiteAppSettings together via MultiAppSettings, but would prefer to pre-read all the database settings in one call versus on demand, is there a way to do that, so that everything is in memory?

Below is the relevant code:

        OracleDialect.Provider.NamingStrategy = new OrmLiteNamingStrategyBase();
        OracleDialect.Provider.StringSerializer = new JsonStringSerializer();

        var fileSettings = new TextFileSettings(ConfigUtils.GetAppSetting("PathToSecuredFile"));
        var dbFactory = new OrmLiteConnectionFactory(fileSettings.GetString("LeadDbConfigKey"), OracleOrmLiteDialectProvider.Instance);
        var dbSettings = new OrmLiteAppSettings(dbFactory);
        var multiSettings = new MultiAppSettings(fileSettings, dbSettings);
        container.Register<IAppSettings>(c => multiSettings);

Thank you, Stephen


Solution

  • To preload all db App Settings you can just read the entire ConfigSetting db table into a .NET Dictionary and wrap it in DictionarySettings, e.g:

    using (db = dbFactory.Open())
    {
        var allDbSettings = db.Dictionary<string,string>(
            db.From<ConfigSetting>().Select(x => new { x.Id, x.Value}));
    
        var multiSettings = new MultiAppSettings(
            fileSettings, 
            new DictionarySettings(allDbSettings));
    }