Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

SettingsManager and ISettingStore #2660


User avatar
0
bilalhaidar created

Hello,

I am browsing the framework code and noticed this code:

public SettingManager(ISettingDefinitionManager settingDefinitionManager, ICacheManager cacheManager)
        {
            _settingDefinitionManager = settingDefinitionManager;

            AbpSession = NullAbpSession.Instance;
            SettingStore = DefaultConfigSettingStore.Instance;

As you can see it is using the DefaultconfigSettingStore.

Later on, in the Abp.Zero, it defines a new SettingStore.

Where in the solutions, you configure it to use the Abp.Zero.SettingStore and not the default?

Also, every module can have a SettingsProvider to return Settings. Where in the solutions, do you capture all those settings from each module and store them in db?

Many thanks, Bilal


12 Answer(s)
  • User Avatar
    0
    bilalhaidar created

    Any idea?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    When a new module adds the same implementation of a class, it is used by default. So module zero adds the implementation.

    About registering setting definitions, it is done in SettingDefinitionManager's Initialize method.

  • User Avatar
    0
    bilalhaidar created

    Great, I can see it now.

    In the DefinitionManager.Initialize() it saves all settings from all providers.

    SetingsManager uses the SettingsStore to persist to DB.

    I still have one missing link: SettingsManager, where is it called to persist whatever settings DefinitionManager has? I tried to look for that, but couldn't.

    When searching for code how it works, is there like a guide or logical path to follow or starting point?

    Thanks Ismail :)

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    It is stored by SettingStore, see <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/master/src/Abp.Zero/Configuration/SettingStore.cs">https://github.com/aspnetboilerplate/mo ... ngStore.cs</a>.

    Actually you can use AbpKernelModule for tracking such cases, <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp/AbpKernelModule.cs">https://github.com/aspnetboilerplate/as ... lModule.cs</a>.

  • User Avatar
    0
    bilalhaidar created

    Thanks Ismail.

    SettingsManger calls SettingsStore to persist data into DB.

    Who calls SettingsManager to persist? Where in time does this happen?

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    It happens when you call it in your code.

  • User Avatar
    0
    bilalhaidar created

    An example maybe? Where does that show? Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    TenantSettingsAppService and HostSettingsAppService are examples of it, you can take a look at them.

  • User Avatar
    0
    bilalhaidar created

    Great!

    But still first time application loads, who asks the SettingsManager to save any settings in DB? I am sure there are some settings set by SettingsProviders in different modules.

    There might be something missing for me, dunno.

    Thanks again

  • User Avatar
    0
    bilalhaidar created

    Hi Ismail, I guess I was missing one thing, SettingsDefinitionManager is defined as "Singleton" in the IoC. Therefore, every time the application runs, the settings will be collected from all modules and will be available.

    When a change occurs in Tenant Settings or Host Settings, then values are written on-demand to DB.

    I am not sure though, if the values stored in memory are updated on the spot, or next time they are requested they are read from DB.

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    If value of a setting changes, it is updated both in database and setting manager, see <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp/Configuration/SettingManager.cs#L261">https://github.com/aspnetboilerplate/as ... er.cs#L261</a>.

    There is only one thing, settings are accesible on the client side via "abp.setting.values["NameOfSetting"]". If your setting change request is an ajax request, this client side value is not updated, you will need a page refresh in this case or you can update the client side value as well using regular javascript code like:

    abp.setting.values["NameOfSetting"] = "new value for setting";
    
  • User Avatar
    0
    bilalhaidar created

    Thanks!