using System.Threading.Tasks;
namespace Abp.Application.Features
{
///
/// Most simple implementation of .
/// It checks one or more features if they are enabled.
///
public class SimpleFeatureDependency : IFeatureDependency
{
///
/// A list of features to be checked if they are enabled.
///
public string[] Features { get; set; }
///
/// If this property is set to true, all of the must be enabled.
/// If it's false, at least one of the must be enabled.
/// Default: false.
///
public bool RequiresAll { get; set; }
///
/// Initializes a new instance of the class.
///
/// The features.
public SimpleFeatureDependency(params string[] features)
{
Features = features;
}
///
/// Initializes a new instance of the class.
///
///
/// If this is set to true, all of the must be enabled.
/// If it's false, at least one of the must be enabled.
///
/// The features.
public SimpleFeatureDependency(bool requiresAll, params string[] features)
: this(features)
{
RequiresAll = requiresAll;
}
///
public Task IsSatisfiedAsync(IFeatureDependencyContext context)
{
return context.TenantId.HasValue
? context.FeatureChecker.IsEnabledAsync(context.TenantId.Value, RequiresAll, Features)
: context.FeatureChecker.IsEnabledAsync(RequiresAll, Features);
}
}
}