public void NestedConfigTest() { IRootBaseSetting settings = MyAppCfg.Get <IRootBaseSetting>(); DoRootTest(settings); DoNestedTest(settings.NestedSettings); }
public void Init() { // register custom setting parsers MyAppCfg.TypeParsers.Register(new TimeToRunParser()); MyAppCfg.TypeParsers.Register(new RandomTimeSpanParser()); Base = MyAppCfg.Get <ISettings>(); }
public void Setup() { // setup json serializer settings MyAppCfg.JsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings { DateFormatString = "dd+MM+yyyy" // ex: setup default format }; settings = MyAppCfg.Get <IJsonItemSetting>(); }
static void Main(string[] args) { MySettings.Init(); var settingsWithoutTenant = MyAppCfg.Get <IRedisSetting>(); var settingsWithTenant = MyAppCfg.Get <IRedisSetting>("demo-tenant"); Console.WriteLine($"Without Tenant: {settingsWithoutTenant.ASettingFromDb_Text}"); Console.WriteLine($"Without Tenant: {settingsWithoutTenant.ASettingFromDb_Stored}"); Console.WriteLine(); Console.WriteLine($"With Tenant: {settingsWithTenant.ASettingFromDb_Text}"); Console.WriteLine($"With Tenant: {settingsWithTenant.ASettingFromDb_Stored}"); Console.ReadKey(); }
public static void Init() { // by default, AppCfg will auto create [JsonParser] for json type (IJsonDataType) at runtime // so, if you want to overwrite it by your parser [DemoParserWithRawBuilder] then you have to register it MyAppCfg.TypeParsers.Register(new DemoParserWithRawBuilder <JsonPerson>()); // setup json serializer settings MyAppCfg.JsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings { DateFormatString = "dd+MM+yyyy" // ex: setup default format }; // inital settings BaseSettings = MyAppCfg.Get <ISetting>(); JsonSettings = MyAppCfg.Get <IJsonSetting>(); ConnSettings = MyAppCfg.Get <IConnectionStringSetting>(); }
public static void Init() { MyAppCfg.SettingStores.RegisterCustomStore(StoreKey_MSSQL_With_CommandText, opt => { var connectionString = ConfigurationManager.ConnectionStrings["myConn"].ConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); var sqlText = string.Empty; if (string.IsNullOrWhiteSpace(opt.TenantKey)) { sqlText = $"SELECT TOP 1 [Value] FROM [GlobalSettings] WHERE [TenantId] IS NULL AND [Name] = '{opt.SettingKey}'"; } else { sqlText = $"SELECT TOP 1 [Value] FROM [GlobalSettings] WHERE [TenantId] = '{opt.TenantKey}' AND [Name] = '{opt.SettingKey}'"; } using (SqlCommand command = new SqlCommand(sqlText, connection)) { command.CommandType = System.Data.CommandType.Text; using (var reader = command.ExecuteReader()) { while (reader.Read()) { return(reader.GetString(0)); } } return(null); } } }); MyAppCfg.SettingStores.RegisterCustomStore(StoreKey_MSSQL_With_StoredProc, opt => { var connectionString = ConfigurationManager.ConnectionStrings["myConn"].ConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("dbo.AppCfgGetSetting", connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@appcfg_tenant_name", opt.TenantKey ?? (object)DBNull.Value)); command.Parameters.Add(new SqlParameter("@appcfg_setting_name", opt.SettingKey)); using (var reader = command.ExecuteReader()) { while (reader.Read()) { return(reader.GetString(0)); } } return(null); } } }); // inital settings BaseSettings = MyAppCfg.Get <IMssqlSetting>(); BaseSettingsWithTenant = MyAppCfg.Get <IMssqlSetting>("I am a tenant"); }
public void Setup() { MyAppCfg.TypeParsers.Register(new ParserWithRawBuilder <JsonPersonTestModel>()); settings = MyAppCfg.Get <ICustomParserSettings>(); }
public void Init() { Base = MyAppCfg.Get <IAppSettings>(); }