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; }
private readonly IFeatureManager _featureManager;
private readonly IFeatureDefinitionManager _featureDefinitionManager;
private readonly IStringLocalizerFactory _stringLocalizerFactory;
protected IFeatureManager FeatureManager { get; }
protected IFeatureDefinitionManager FeatureDefinitionManager { get; }
public FeatureAppService(IFeatureManager featureManager,
IFeatureDefinitionManager featureDefinitionManager,
IStringLocalizerFactory stringLocalizerFactory,
IOptions<FeatureManagementOptions> options)
{
_featureManager = featureManager;
_featureDefinitionManager = featureDefinitionManager;
_stringLocalizerFactory = stringLocalizerFactory;
FeatureManager = featureManager;
FeatureDefinitionManager = featureDefinitionManager;
Options = options.Value;
}
@ -36,7 +33,7 @@ namespace Volo.Abp.FeatureManagement
{
await CheckProviderPolicy(providerName);
var featureDefinitions = _featureDefinitionManager.GetAll();
var featureDefinitions = FeatureDefinitionManager.GetAll();
var features = new List<FeatureDto>();
foreach (var featureDefinition in featureDefinitions)
@ -44,11 +41,11 @@ namespace Volo.Abp.FeatureManagement
features.Add(new FeatureDto
{
Name = featureDefinition.Name,
DisplayName = featureDefinition.DisplayName?.Localize(_stringLocalizerFactory),
DisplayName = featureDefinition.DisplayName?.Localize(StringLocalizerFactory),
ValueType = featureDefinition.ValueType,
Description = featureDefinition.Description?.Localize(_stringLocalizerFactory),
Description = featureDefinition.Description?.Localize(StringLocalizerFactory),
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)
{
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)
{
foreach (var feature in features)

@ -8,17 +8,17 @@ namespace Volo.Abp.FeatureManagement
{
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);
}
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.");
}
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.");
}

@ -14,7 +14,7 @@ namespace Volo.Abp.FeatureManagement
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));
}

@ -21,13 +21,13 @@ namespace Volo.Abp.FeatureManagement
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);
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);
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);
if (featureValue != null)

@ -13,7 +13,7 @@ namespace Volo.Abp.FeatureManagement
FeatureManagementStore = featureManagementStore;
}
public Task<string> GetOrNullAsync(
public virtual Task<string> GetOrNullAsync(
string name,
string providerName,
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
.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
.Where(

@ -8,21 +8,21 @@ namespace Volo.Abp.FeatureManagement
[Area("abp")]
public class FeaturesController : AbpController, IFeatureAppService
{
private readonly IFeatureAppService _featureAppService;
protected IFeatureAppService FeatureAppService { get; }
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()
.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()
.Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey)

@ -25,21 +25,21 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement
public FeatureListDto FeatureListDto { get; set; }
private readonly IFeatureAppService _featureAppService;
protected IFeatureAppService FeatureAppService { get; }
public FeatureManagementModal(IFeatureAppService featureAppService)
{
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
{
@ -50,7 +50,7 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement
}).ToList()
};
await _featureAppService.UpdateAsync(ProviderName, ProviderKey, features);
await FeatureAppService.UpdateAsync(ProviderName, ProviderKey, features);
return NoContent();
}

Loading…
Cancel
Save