Open Closed

Angular ConfigStateService not getting settings defined in appSettings.json on Host. #7255


User avatar
0
Chris.Didonna created
  • ABP Framework version: v5.3.0
  • UI Type: Angular
  • Database System: EF Core (PostgreSQL)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no

I've got some settings defined in appSettings.json in my HttpApi.Host project and I have also defined a SettingDefinitionProvider to make them visible to clients (I assume that's what I have to do from reading the Settings documentation).

The SettingsProvider can't find the settings by name, do I have to define them somewhere else as well?

  public class AzureSettingsProvider : SettingDefinitionProvider
    {
        public override void Define(ISettingDefinitionContext context)
        { 
            var clientId = context.GetOrNull("Azure.B2C.ClientId");
            clientId.IsVisibleToClients = true;
            var tenant = context.GetOrNull("Azure.B2C.Tenant");
            tenant.IsVisibleToClients = true; 
            var PasswordEndpoint = context.GetOrNull("Azure.B2C.PasswordEndpoint");
            PasswordEndpoint.IsVisibleToClients = true; 
            var PrimaryDomain = context.GetOrNull("Azure.B2C.PrimaryDomain");
            PrimaryDomain.IsVisibleToClients = true;
        }
    }

Using the ConfigStateService on my Angular client, it isn't getting the values, it always returns undefined.

import { ConfigStateService } from '@abp/ng.core';

constructor(private config: ConfigStateService,
              private router: Router,) {
    var endpoint = this.config.getOne('Azure.B2C.PasswordEndpoint');
    var tenant = this.config.getOne('Azure.B2C.Tenant');
    var domain = this.config.getOne('Azure.B2C.PrimaryDomain');
    var clientid = this.config.getOne('Azure.B2C.ClientId');

Doesn't matter if I use getOne or getSetting.

What's missing or what have I interpreted wrong?

I've tested this approach with 'Abp.Mailing.Smtp.Host' and the value appears so I don't know what's missing for the settings I've named myself.


9 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Could you please share the full steps to reproduce? I will check it.

  • User Avatar
    0
    Chris.Didonna created

    There's not much else to tell really.

    1. Make a setting in appSettings.json for your HttpApi.Host project
    2. Make a SettingsDefinitionProvider and retrieve the setting so you can set it's field 'IsVisibleToClients' to true.
    3. Add ConfigStateService to a component in your Angular app.
    4. Use getSetting to get the value of the setting.

    This all worked with the pre-built ABP setting, 'Abp.Mailing.Smtp.Host' but not with one that I've defined.

  • User Avatar
    0
    Chris.Didonna created

    I also tried adding a context.Add(new SettingDefinition("SomeSetting", "SomeValue") inside the AzureSettingsProvider.Define method to see if that would show up, still nothing in the Angular side.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I could not reproduce the problem.

    Here is how ABP defines settings you can check. https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/EmailSettingProvider.cs#L11

    I will check if you can share a simple project with me via mail. shiwei.liang@volosoft.com

  • User Avatar
    0
    Chris.Didonna created

    Did you do it in version 5.3.0? Did you define a new setting name, not a default part of the ABP framework? Did you do it in appSettings.json?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    yes

  • User Avatar
    0
    Chris.Didonna created

    Ok, created a new Acme.Bookstore solution from scratch and made the changes

    My provider looks like this:

    using Volo.Abp.Settings;
    
    namespace Acme.BookStore.Provider
    {
        public class SettingsProvider : SettingDefinitionProvider
        {
            public override void Define(ISettingDefinitionContext context)
            {
                var test = context.GetOrNull("Abp.Mailing.Smtp.Host");
                test.IsVisibleToClients = true;
    
    
            }
        }
    }
    

    My appSettings.json like this:

      "Settings": {
        "Abp.Mailing.Smtp.Host": "127.0.0.1"
      }
    

    That one it finds, sets and shows in the UI.

    If I add anything else, even a ABP setting, it can't find the setting in the provider.

    Is there something else I have to set up for a Setting other than just putting it in appSettings.json?

  • User Avatar
    0
    Chris.Didonna created

    Hi,

    I could not reproduce the problem.

    Here is how ABP defines settings you can check. https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/EmailSettingProvider.cs#L11

    I will check if you can share a simple project with me via mail. shiwei.liang@volosoft.com

    My sample HttpApi.Host project zipped is 37MB I don't think I can email that.

  • User Avatar
    0
    Chris.Didonna created

    Ok got it working like this

    context.Add(new SettingDefinition("Volo.Abp.LeptonTheme.Style", isVisibleToClients: true));

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38