Merge pull request #3177 from abpframework/Cotur-Virtualization-FeatureManagement

Make FeatureManagement module services easily overridable by inheritance
pull/3150/head^2
Halil İbrahim Kalkan 5 years ago committed by GitHub
commit ead9f06836
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,18 +17,15 @@ namespace Volo.Abp.FeatureManagement
{ {
protected FeatureManagementOptions Options { get; } protected FeatureManagementOptions Options { get; }
private readonly IFeatureManager _featureManager; protected IFeatureManager FeatureManager { get; }
private readonly IFeatureDefinitionManager _featureDefinitionManager; protected IFeatureDefinitionManager FeatureDefinitionManager { get; }
private readonly IStringLocalizerFactory _stringLocalizerFactory;
public FeatureAppService(IFeatureManager featureManager, public FeatureAppService(IFeatureManager featureManager,
IFeatureDefinitionManager featureDefinitionManager, IFeatureDefinitionManager featureDefinitionManager,
IStringLocalizerFactory stringLocalizerFactory,
IOptions<FeatureManagementOptions> options) IOptions<FeatureManagementOptions> options)
{ {
_featureManager = featureManager; FeatureManager = featureManager;
_featureDefinitionManager = featureDefinitionManager; FeatureDefinitionManager = featureDefinitionManager;
_stringLocalizerFactory = stringLocalizerFactory;
Options = options.Value; Options = options.Value;
} }
@ -36,7 +33,7 @@ namespace Volo.Abp.FeatureManagement
{ {
await CheckProviderPolicy(providerName); await CheckProviderPolicy(providerName);
var featureDefinitions = _featureDefinitionManager.GetAll(); var featureDefinitions = FeatureDefinitionManager.GetAll();
var features = new List<FeatureDto>(); var features = new List<FeatureDto>();
foreach (var featureDefinition in featureDefinitions) foreach (var featureDefinition in featureDefinitions)
@ -44,11 +41,11 @@ namespace Volo.Abp.FeatureManagement
features.Add(new FeatureDto features.Add(new FeatureDto
{ {
Name = featureDefinition.Name, Name = featureDefinition.Name,
DisplayName = featureDefinition.DisplayName?.Localize(_stringLocalizerFactory), DisplayName = featureDefinition.DisplayName?.Localize(StringLocalizerFactory),
ValueType = featureDefinition.ValueType, ValueType = featureDefinition.ValueType,
Description = featureDefinition.Description?.Localize(_stringLocalizerFactory), Description = featureDefinition.Description?.Localize(StringLocalizerFactory),
ParentName = featureDefinition.Parent?.Name, ParentName = featureDefinition.Parent?.Name,
Value = await _featureManager.GetOrNullAsync(featureDefinition.Name, providerName, providerKey) Value = await FeatureManager.GetOrNullAsync(featureDefinition.Name, providerName, providerKey)
}); });
} }
@ -63,11 +60,11 @@ namespace Volo.Abp.FeatureManagement
foreach (var feature in input.Features) foreach (var feature in input.Features)
{ {
await _featureManager.SetAsync(feature.Name, feature.Value, providerName, providerKey); await FeatureManager.SetAsync(feature.Name, feature.Value, providerName, providerKey);
} }
} }
private void SetFeatureDepth(List<FeatureDto> features, string providerName, string providerKey, protected virtual void SetFeatureDepth(List<FeatureDto> features, string providerName, string providerKey,
FeatureDto parentFeature = null, int depth = 0) FeatureDto parentFeature = null, int depth = 0)
{ {
foreach (var feature in features) foreach (var feature in features)

@ -8,17 +8,17 @@ namespace Volo.Abp.FeatureManagement
{ {
public string Name => DefaultValueFeatureValueProvider.ProviderName; public string Name => DefaultValueFeatureValueProvider.ProviderName;
public Task<string> GetOrNullAsync(FeatureDefinition feature, string providerKey) public virtual Task<string> GetOrNullAsync(FeatureDefinition feature, string providerKey)
{ {
return Task.FromResult(feature.DefaultValue); return Task.FromResult(feature.DefaultValue);
} }
public Task SetAsync(FeatureDefinition feature, string value, string providerKey) public virtual Task SetAsync(FeatureDefinition feature, string value, string providerKey)
{ {
throw new AbpException($"Can not set default value of a feature. It is only possible while defining the feature in a {typeof(IFeatureDefinitionProvider)} implementation."); throw new AbpException($"Can not set default value of a feature. It is only possible while defining the feature in a {typeof(IFeatureDefinitionProvider)} implementation.");
} }
public Task ClearAsync(FeatureDefinition feature, string providerKey) public virtual Task ClearAsync(FeatureDefinition feature, string providerKey)
{ {
throw new AbpException($"Can not clear default value of a feature. It is only possible while defining the feature in a {typeof(IFeatureDefinitionProvider)} implementation."); throw new AbpException($"Can not clear default value of a feature. It is only possible while defining the feature in a {typeof(IFeatureDefinitionProvider)} implementation.");
} }

@ -14,7 +14,7 @@ namespace Volo.Abp.FeatureManagement
Store = store; Store = store;
} }
public async Task<string> GetOrNullAsync(FeatureDefinition feature, string providerKey) public virtual async Task<string> GetOrNullAsync(FeatureDefinition feature, string providerKey)
{ {
return await Store.GetOrNullAsync(feature.Name, Name, NormalizeProviderKey(providerKey)); return await Store.GetOrNullAsync(feature.Name, Name, NormalizeProviderKey(providerKey));
} }

@ -21,13 +21,13 @@ namespace Volo.Abp.FeatureManagement
Cache = cache; Cache = cache;
} }
public async Task<string> GetOrNullAsync(string name, string providerName, string providerKey) public virtual async Task<string> GetOrNullAsync(string name, string providerName, string providerKey)
{ {
var cacheItem = await GetCacheItemAsync(name, providerName, providerKey); var cacheItem = await GetCacheItemAsync(name, providerName, providerKey);
return cacheItem.Value; return cacheItem.Value;
} }
public async Task SetAsync(string name, string value, string providerName, string providerKey) public virtual async Task SetAsync(string name, string value, string providerName, string providerKey)
{ {
var featureValue = await FeatureValueRepository.FindAsync(name, providerName, providerKey); var featureValue = await FeatureValueRepository.FindAsync(name, providerName, providerKey);
if (featureValue == null) if (featureValue == null)
@ -42,7 +42,7 @@ namespace Volo.Abp.FeatureManagement
} }
} }
public async Task DeleteAsync(string name, string providerName, string providerKey) public virtual async Task DeleteAsync(string name, string providerName, string providerKey)
{ {
var featureValue = await FeatureValueRepository.FindAsync(name, providerName, providerKey); var featureValue = await FeatureValueRepository.FindAsync(name, providerName, providerKey);
if (featureValue != null) if (featureValue != null)

@ -13,7 +13,7 @@ namespace Volo.Abp.FeatureManagement
FeatureManagementStore = featureManagementStore; FeatureManagementStore = featureManagementStore;
} }
public Task<string> GetOrNullAsync( public virtual Task<string> GetOrNullAsync(
string name, string name,
string providerName, string providerName,
string providerKey) string providerKey)

@ -15,7 +15,7 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore
{ {
} }
public async Task<FeatureValue> FindAsync(string name, string providerName, string providerKey) public virtual async Task<FeatureValue> FindAsync(string name, string providerName, string providerKey)
{ {
return await DbSet return await DbSet
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
@ -23,7 +23,7 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore
); );
} }
public async Task<List<FeatureValue>> GetListAsync(string providerName, string providerKey) public virtual async Task<List<FeatureValue>> GetListAsync(string providerName, string providerKey)
{ {
return await DbSet return await DbSet
.Where( .Where(

@ -8,21 +8,21 @@ namespace Volo.Abp.FeatureManagement
[Area("abp")] [Area("abp")]
public class FeaturesController : AbpController, IFeatureAppService public class FeaturesController : AbpController, IFeatureAppService
{ {
private readonly IFeatureAppService _featureAppService; protected IFeatureAppService FeatureAppService { get; }
public FeaturesController(IFeatureAppService featureAppService) public FeaturesController(IFeatureAppService featureAppService)
{ {
_featureAppService = featureAppService; FeatureAppService = featureAppService;
} }
public Task<FeatureListDto> GetAsync(string providerName, string providerKey) public virtual Task<FeatureListDto> GetAsync(string providerName, string providerKey)
{ {
return _featureAppService.GetAsync(providerName, providerKey); return FeatureAppService.GetAsync(providerName, providerKey);
} }
public Task UpdateAsync(string providerName, string providerKey, UpdateFeaturesDto input) public virtual Task UpdateAsync(string providerName, string providerKey, UpdateFeaturesDto input)
{ {
return _featureAppService.UpdateAsync(providerName, providerKey, input); return FeatureAppService.UpdateAsync(providerName, providerKey, input);
} }
} }
} }

@ -16,13 +16,13 @@ namespace Volo.Abp.FeatureManagement.MongoDB
} }
public async Task<FeatureValue> FindAsync(string name, string providerName, string providerKey) public virtual async Task<FeatureValue> FindAsync(string name, string providerName, string providerKey)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey); .FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey);
} }
public async Task<List<FeatureValue>> GetListAsync(string providerName, string providerKey) public virtual async Task<List<FeatureValue>> GetListAsync(string providerName, string providerKey)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey) .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey)

@ -25,21 +25,21 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement
public FeatureListDto FeatureListDto { get; set; } public FeatureListDto FeatureListDto { get; set; }
private readonly IFeatureAppService _featureAppService; protected IFeatureAppService FeatureAppService { get; }
public FeatureManagementModal(IFeatureAppService featureAppService) public FeatureManagementModal(IFeatureAppService featureAppService)
{ {
ObjectMapperContext = typeof(AbpFeatureManagementWebModule); ObjectMapperContext = typeof(AbpFeatureManagementWebModule);
_featureAppService = featureAppService; FeatureAppService = featureAppService;
} }
public async Task OnGetAsync() public virtual async Task OnGetAsync()
{ {
FeatureListDto = await _featureAppService.GetAsync(ProviderName, ProviderKey); FeatureListDto = await FeatureAppService.GetAsync(ProviderName, ProviderKey);
} }
public async Task<IActionResult> OnPostAsync() public virtual async Task<IActionResult> OnPostAsync()
{ {
var features = new UpdateFeaturesDto var features = new UpdateFeaturesDto
{ {
@ -50,7 +50,7 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement
}).ToList() }).ToList()
}; };
await _featureAppService.UpdateAsync(ProviderName, ProviderKey, features); await FeatureAppService.UpdateAsync(ProviderName, ProviderKey, features);
return NoContent(); return NoContent();
} }

Loading…
Cancel
Save