Hello, I'm trying to obtain a Setting inside a xUnit Test.
Via GetSettingValueForTenant, the system says that no Setting for this "name" exist. Buy If I get an GetAllSettingValuesForTenant, I can see the value... There is a snippet:
string name = "Project.bd22b07c-a0f1-4cd5-b759-a054ba60673b.SdFileWriterChannel.FileRepo";
// HERE I GOT AN ERROR var test = _settingManager.GetSettingValueForTenant(name, tenantId.GetValueOrDefault());
// BUT NOT HERE... IReadOnlyList<ISettingValue> settings = _settingManager.GetAllSettingValuesForTenant (tenantId.GetValueOrDefault()); foreach (var item in settings) { if(item.Name.Equals(name)) { return item.Value; } }
Am I missing something?
Kind regards, Oscar
3 Answer(s)
-
0
Hi @oscargonzalezmoreno,
Can you also share your setting definition ?
-
0
Hello, I'm not using Setting Definition, I'm just pre-inserting the data in the database. Maybe it's the problem, but as I said, I don't understand how I can get the Setting value with the second method...
-
0
ABP is open source, so you can check the implementation in SettingManager.cs.
GetSettingValueForTenant calls _settingDefinitionManager.GetSettingDefinition(name), which does:
_settings.TryGetValue(name, out settingDefinition)
On the other hand, GetAllSettingValuesForTenant calls SettingStore.GetAllListAsync(tenantId, null), which does:
_settingRepository.GetAllListAsync(s => s.UserId == userId && s.TenantId == tenantId)
So, these are for different purposes:
- The first gets the predefined setting, even if not overridden for the specified tenant.
- The second gets all settings from DB, but only if overridden for the specified tenant.
If you insist on not defining settings, the second way is an undocumented (non-guaranteed) way of getting the setting value.