question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[NotAnIssue] Why Setting Management works in this way?

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
acjhcommented, Nov 19, 2018

So why default values are that much important?

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

0reactions
iyilm4zcommented, Nov 19, 2018

It’s not just default values, but the definitions, that are important. Definitions are for correctness, well-defined behavior and to catch developer errors.

Now it’s clear. Thanks for your concern.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found