- 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
7 Answer(s)
-
1
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
GetSettingValueInternalAsyncandGetSettingValueInternalmethods 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);Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
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?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
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.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
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.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @rcasaca
If you need two new methods, I think it will be better to create extension methods for SettingManager.
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?
Could you share which methods ?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi ismcagdas,
Sorry for the late reply. I'm still trying to accomplish this. I'm not being able to Replace ISettingManager built in by my new one. The error ComponentNotFoundException: No component for supporting the service CustomerHub.Configuration.IHubSettingManager was found is thrown.
This is what i have in Web.Mvc.CustomerHubWebMvcModule.PreInitialize
Configuration.ReplaceService<ISettingManager, HubSettingManager>(DependencyLifeStyle.Singleton);I've already have my own IHubSettingManager
public interface IHubSettingManager { Task<string> GetSettingAsync(string Name, long UserId); }implemented by HubSettingManager
public class HubSettingManager : SettingManager, IHubSettingManager { public HubSettingManager( ISettingDefinitionManager settingDefinitionManager, ICacheManager cacheManager, IMultiTenancyConfig multiTenancyConfig, ITenantStore tenantStore, ISettingEncryptionService settingEncryptionService) : base( settingDefinitionManager, cacheManager, multiTenancyConfig, tenantStore, settingEncryptionService) { } public async Task<string> GetSettingAsync(string Name, long UserId) { return "setting.value"; } }What i'm I missing?
Thanks.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
It seems like IHubSettingManager is not registered to DI. Could you change its definition as shown below;
public interface IHubSettingManager : ISingletonDependency { Task<string> GetSettingAsync(string Name, long UserId); }Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)