Open Closed

New Settings Scopes #10355


0
rcasaca created
  • What is your product version?
    • 10.0.0
  • What is your product type (Angular or MVC)?
    • MVC
  • What is product framework type (.net framework or .net core)?
    • .net core

How can i add a new SettingScope? I need some settings to be linked to User and their Companies or Working Sites. When retrieved they should fallback up to Company starting at User level.

Do i need to create a specific Setting entity? Also a new SettingManager?

Any tip? Thanks


4 Answer(s)
  • 1
    ismcagdas created
    Support Team

    Hi,

    It is a bit hard to add a new SettingScope. SettingScopes are defined as enum, https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Configuration/SettingScope.cs.

    Duplicating the entire logic will be hard. You can try to create your own SettingManager inheriting from default SettingManager and override GetSettingValueInternalAsync and GetSettingValueInternal methods to include your logic.

    Finally, you need to replace default Setting manager with your version in PreInitialize method of your Core module as shown below;

    Configuration.ReplaceService<ISettingManager, MySettingManager>(DependencyLifeStyle.Singleton);

  • 0
    rcasaca created

    Hi ismcagdas, Ok, i was able to apply your suggestion but since i also need to relate settings with Company e WorkingSites structure. I can't use existing SettingDefinitions. Should i create a new SettingDefiition? New Entity to store them in database?

  • 0
    ismcagdas created
    Support Team

    Hi,

    SettingDefinition is not an Entity, https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Zero.Common/Configuration/Setting.cs is used as an Entity. So, you can relate this one with your entity. SettingDefinition is mapped to Setting when saving to DB.

  • 0
    rcasaca created

    Hi ismcagdas, I've extended Setting entity following this tutorial https://docs.aspnetzero.com/en/common/latest/Extending-Existing-Entities#extending-non-abstract-entities. It added two fields, the fk I needed and Discriminator.

    You've mention to create a new SettingManager inheriting from default one, I was able to do that, also replacing the service ISettingManager in PreInitialize on WebMvcModule, but it doesn't allow me to override those methods. Also, I can't see them in default SettingManager as well. I'm I missing something? I accomplish that by replicate the method GetSettingValueForUserAsync in my AppHubSettingProvider.

    Nevertheless i'm still missing two more methods, Save and Get based on related entity. Like GetSettingValueForApplication, ChangeSettingForApplication. Should I extend interface SettingManager or create a new one?

    Thanks.