using System.Threading.Tasks; using Abp.Dependency; using Abp.Runtime.Session; namespace Abp.Application.Features { /// /// Default implementation for . /// public class FeatureChecker : IFeatureChecker, ITransientDependency { /// /// Reference to the current session. /// public IAbpSession AbpSession { get; set; } /// /// Reference to the store used to get feature values. /// public IFeatureValueStore FeatureValueStore { get; set; } private readonly IFeatureManager _featureManager; /// /// Creates a new object. /// public FeatureChecker(IFeatureManager featureManager) { _featureManager = featureManager; FeatureValueStore = NullFeatureValueStore.Instance; AbpSession = NullAbpSession.Instance; } /// public Task GetValueAsync(string name) { if (!AbpSession.TenantId.HasValue) { throw new AbpException("FeatureChecker can not get a feature value by name. TenantId is not set in the IAbpSession!"); } return GetValueAsync(AbpSession.TenantId.Value, name); } /// public async Task GetValueAsync(int tenantId, string name) { var feature = _featureManager.Get(name); var value = await FeatureValueStore.GetValueOrNullAsync(tenantId, feature); if (value == null) { return feature.DefaultValue; } return value; } } }