ISettingManager.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. namespace Abp.Configuration
  5. {
  6. /// <summary>
  7. /// This is the main interface that must be implemented to be able to load/change values of settings.
  8. /// </summary>
  9. public interface ISettingManager
  10. {
  11. /// <summary>
  12. /// Gets current value of a setting.
  13. /// It gets the setting value, overwritten by application, current tenant and current user if exists.
  14. /// </summary>
  15. /// <param name="name">Unique name of the setting</param>
  16. /// <returns>Current value of the setting</returns>
  17. Task<string> GetSettingValueAsync(string name);
  18. /// <summary>
  19. /// Gets current value of a setting for the application level.
  20. /// </summary>
  21. /// <param name="name">Unique name of the setting</param>
  22. /// <returns>Current value of the setting for the application</returns>
  23. Task<string> GetSettingValueForApplicationAsync(string name);
  24. /// <summary>
  25. /// Gets current value of a setting for the application level.
  26. /// If fallbackToDefault is false, it just gets value from application and returns null if application has not defined a value for the setting.
  27. /// </summary>
  28. /// <param name="name">Unique name of the setting</param>
  29. /// <param name="fallbackToDefault"></param>
  30. /// <returns>Current value of the setting for the application</returns>
  31. Task<string> GetSettingValueForApplicationAsync(string name, bool fallbackToDefault);
  32. /// <summary>
  33. /// Gets current value of a setting for a tenant level.
  34. /// It gets the setting value, overwritten by given tenant.
  35. /// </summary>
  36. /// <param name="name">Unique name of the setting</param>
  37. /// <param name="tenantId">Tenant id</param>
  38. /// <returns>Current value of the setting</returns>
  39. Task<string> GetSettingValueForTenantAsync(string name, int tenantId);
  40. /// <summary>
  41. /// Gets current value of a setting for a tenant level.
  42. /// It gets the setting value, overwritten by given tenant if fallbackToDefault is true.
  43. /// If fallbackToDefault is false, it just gets value from tenant and returns null if tenant has not defined a value for the setting.
  44. /// </summary>
  45. /// <param name="name">Unique name of the setting</param>
  46. /// <param name="tenantId">Tenant id</param>
  47. /// <param name="fallbackToDefault"></param>
  48. /// <returns>Current value of the setting</returns>
  49. Task<string> GetSettingValueForTenantAsync(string name, int tenantId, bool fallbackToDefault);
  50. /// <summary>
  51. /// Gets current value of a setting for a user level.
  52. /// It gets the setting value, overwritten by given tenant and user.
  53. /// </summary>
  54. /// <param name="name">Unique name of the setting</param>
  55. /// <param name="tenantId">Tenant id</param>
  56. /// <param name="userId">User id</param>
  57. /// <returns>Current value of the setting for the user</returns>
  58. Task<string> GetSettingValueForUserAsync(string name, int? tenantId, long userId);
  59. /// <summary>
  60. /// Gets current value of a setting for a user level.
  61. /// It gets the setting value, overwritten by given tenant and user if fallbackToDefault is true.
  62. /// If fallbackToDefault is false, it just gets value from user and returns null if user has not defined a value for the setting.
  63. /// </summary>
  64. /// <param name="name">Unique name of the setting</param>
  65. /// <param name="tenantId">Tenant id</param>
  66. /// <param name="userId">User id</param>
  67. /// <param name="fallbackToDefault"></param>
  68. /// <returns>Current value of the setting for the user</returns>
  69. Task<string> GetSettingValueForUserAsync(string name, int? tenantId, long userId, bool fallbackToDefault);
  70. /// <summary>
  71. /// Gets current value of a setting for a user level.
  72. /// It gets the setting value, overwritten by given tenant and user.
  73. /// </summary>
  74. /// <param name="name">Unique name of the setting</param>
  75. /// <param name="user">User</param>
  76. /// <returns>Current value of the setting for the user</returns>
  77. Task<string> GetSettingValueForUserAsync(string name, UserIdentifier user);
  78. /// <summary>
  79. /// Gets current values of all settings.
  80. /// It gets all setting values, overwritten by application, current tenant (if exists) and the current user (if exists).
  81. /// </summary>
  82. /// <returns>List of setting values</returns>
  83. Task<IReadOnlyList<ISettingValue>> GetAllSettingValuesAsync();
  84. /// <summary>
  85. /// Gets current values of all settings.
  86. /// It gets default values of all settings then overwrites by given scopes.
  87. /// </summary>
  88. /// <param name="scopes">One or more scope to overwrite</param>
  89. /// <returns>List of setting values</returns>
  90. Task<IReadOnlyList<ISettingValue>> GetAllSettingValuesAsync(SettingScopes scopes);
  91. /// <summary>
  92. /// Gets a list of all setting values specified for the application.
  93. /// It returns only settings those are explicitly set for the application.
  94. /// If a setting's default value is used, it's not included the result list.
  95. /// If you want to get current values of all settings, use <see cref="GetAllSettingValuesAsync()"/> method.
  96. /// </summary>
  97. /// <returns>List of setting values</returns>
  98. Task<IReadOnlyList<ISettingValue>> GetAllSettingValuesForApplicationAsync();
  99. /// <summary>
  100. /// Gets a list of all setting values specified for a tenant.
  101. /// It returns only settings those are explicitly set for the tenant.
  102. /// If a setting's default value is used, it's not included the result list.
  103. /// If you want to get current values of all settings, use <see cref="GetAllSettingValuesAsync()"/> method.
  104. /// </summary>
  105. /// <param name="tenantId">Tenant to get settings</param>
  106. /// <returns>List of setting values</returns>
  107. Task<IReadOnlyList<ISettingValue>> GetAllSettingValuesForTenantAsync(int tenantId);
  108. /// <summary>
  109. /// Gets a list of all setting values specified for a user.
  110. /// It returns only settings those are explicitly set for the user.
  111. /// If a setting's value is not set for the user (for example if user uses the default value), it's not included the result list.
  112. /// If you want to get current values of all settings, use <see cref="GetAllSettingValuesAsync()"/> method.
  113. /// </summary>
  114. /// <param name="user">User to get settings</param>
  115. /// <returns>All settings of the user</returns>
  116. Task<IReadOnlyList<ISettingValue>> GetAllSettingValuesForUserAsync(UserIdentifier user);
  117. /// <summary>
  118. /// Changes setting for the application level.
  119. /// </summary>
  120. /// <param name="name">Unique name of the setting</param>
  121. /// <param name="value">Value of the setting</param>
  122. Task ChangeSettingForApplicationAsync(string name, string value);
  123. /// <summary>
  124. /// Changes setting for a Tenant.
  125. /// </summary>
  126. /// <param name="tenantId">TenantId</param>
  127. /// <param name="name">Unique name of the setting</param>
  128. /// <param name="value">Value of the setting</param>
  129. Task ChangeSettingForTenantAsync(int tenantId, string name, string value);
  130. /// <summary>
  131. /// Changes setting for a user.
  132. /// </summary>
  133. /// <param name="user">UserId</param>
  134. /// <param name="name">Unique name of the setting</param>
  135. /// <param name="value">Value of the setting</param>
  136. Task ChangeSettingForUserAsync(UserIdentifier user, string name, string value);
  137. }
  138. }