SimpleFeatureDependency.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Threading.Tasks;
  2. namespace Abp.Application.Features
  3. {
  4. /// <summary>
  5. /// Most simple implementation of <see cref="IFeatureDependency"/>.
  6. /// It checks one or more features if they are enabled.
  7. /// </summary>
  8. public class SimpleFeatureDependency : IFeatureDependency
  9. {
  10. /// <summary>
  11. /// A list of features to be checked if they are enabled.
  12. /// </summary>
  13. public string[] Features { get; set; }
  14. /// <summary>
  15. /// If this property is set to true, all of the <see cref="Features"/> must be enabled.
  16. /// If it's false, at least one of the <see cref="Features"/> must be enabled.
  17. /// Default: false.
  18. /// </summary>
  19. public bool RequiresAll { get; set; }
  20. /// <summary>
  21. /// Initializes a new instance of the <see cref="SimpleFeatureDependency"/> class.
  22. /// </summary>
  23. /// <param name="features">The features.</param>
  24. public SimpleFeatureDependency(params string[] features)
  25. {
  26. Features = features;
  27. }
  28. /// <summary>
  29. /// Initializes a new instance of the <see cref="SimpleFeatureDependency"/> class.
  30. /// </summary>
  31. /// <param name="requiresAll">
  32. /// If this is set to true, all of the <see cref="Features"/> must be enabled.
  33. /// If it's false, at least one of the <see cref="Features"/> must be enabled.
  34. /// </param>
  35. /// <param name="features">The features.</param>
  36. public SimpleFeatureDependency(bool requiresAll, params string[] features)
  37. : this(features)
  38. {
  39. RequiresAll = requiresAll;
  40. }
  41. /// <inheritdoc/>
  42. public Task<bool> IsSatisfiedAsync(IFeatureDependencyContext context)
  43. {
  44. return context.TenantId.HasValue
  45. ? context.FeatureChecker.IsEnabledAsync(context.TenantId.Value, RequiresAll, Features)
  46. : context.FeatureChecker.IsEnabledAsync(RequiresAll, Features);
  47. }
  48. }
  49. }