[NotAnIssue] Why Setting Management works in this way?
See original GitHub issueI have the following senario.
// Step # 1 - Define setting provider
public class AppSettingProvider : SettingProvider {
public override IEnumerable<SettingDefinition> GetSettingDefinitions (SettingDefinitionProviderContext context) {
return new [] {
new SettingDefinition ("App.Test", "Ping",
scopes : SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User,
isVisibleToClients : true)
};
}
}
// Step # 2 - Get setting value - WORKS
var val = SettingManager.GetSettingValue ("App.Test");
// Step # 3 - Ovirride setting for Application, Tenant and User
SettingManager.ChangeSettingForApplication ("App.Test", "Ping_App");
SettingManager.ChangeSettingForTenant (AbpSession.GetTenantId (), "App.Test", "Ping_Tnt");
SettingManager.ChangeSettingForUser (AbpSession.ToUserIdentifier (), "App.Test", "Ping_Usr");
// Step # 4 - Comment out SettingDefinition in AppSettingProvider.
// Because it's overridings are in db now.
public class AppSettingProvider : SettingProvider {
public override IEnumerable<SettingDefinition> GetSettingDefinitions (SettingDefinitionProviderContext context) {
return new [] {
// new SettingDefinition ("App.Test", "Ping",
// scopes : SettingScopes.Application | SettingScopes.Tenant | SettingScopes.User,
// isVisibleToClients : true)
};
}
}
// Step # 5 - Get all setting values for Application, Tenant and User - WORKS
// Because these methods use Setting Store directly.
var settingValuesForApplication = SettingManager.GetAllSettingValuesForApplication ();
var settingValuesForTenant = SettingManager.GetAllSettingValuesForTenant (AbpSession.GetTenantId ());
var settingValuesForUser = SettingManager.GetAllSettingValuesForUser (AbpSession.ToUserIdentifier ());
// Step # 6 - Get setting value like in step # 2 - THROWS EXCEPTİON
// SettingManager.GetSettingValueFor* extension methods also do the same.
// Because GetSettingValue and other extension methods look up the key "App.Test" in a dictionary of Setting Definitions
// we populate by SettingProviders at application's init time.
var newVal = SettingManager.GetSettingValue ("App.Test");
// Step # 7 - Following usings give me what i need but as you see it's a "code smell"
var raz = SettingManager.GetAllSettingValuesForApplication ()
.FirstOrDefault (x => x.Name.Equals ("App.Test"))?.Value;
var dva = SettingManager.GetAllSettingValuesForTenant (AbpSession.GetTenantId ())
.FirstOrDefault (x => x.Name.Equals ("App.Test"))?.Value;
var tri = SettingManager.GetAllSettingValuesForUser (AbpSession.ToUserIdentifier ())
.FirstOrDefault (x => x.Name.Equals ("App.Test"))?.Value;
My question is simple. Why we firstly look up this dictionary to retrive settings? Why i still need to write hard code for each of them, When i already have setting definitions in db?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
DevOpsKit-docs/00c-Addressing-Control-Failures/Readme ...
Failed, NotAnIssue, Passed, Yes, 90, Control has failed. However, the finding does not apply as the control has been implemented in another way....
Read more >The reason people burn out on open source
Toxic culture, loves to point out the tiniest flaws in everyone else's work and don't care or realize that doing so is hurting...
Read more >Changing the ContentType in the http request
Hello, I am looking for a way to change the contenttype in the http request, it seems you can do it in jquery...
Read more >Kent, Laura Acadepic Persstence; Access to Education; *Black ...
Choosing among different types of institution was notan issue. ... The commission on the Higher Education of Minoritie-, viewed its work as.
Read more >saves.
to work, higher taxes could result. If the decision was made to restrict ... Ma has learned the error of his ways ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s not just default values, but the definitions, that are important. Definitions are for correctness, well-defined behavior and to catch developer errors.
The use case you have described is purely static and Step 4 is a developer error. But you can implement your own
ISettingManager
to allow unchecked retrieval.Similar question: #1564
Now it’s clear. Thanks for your concern.