ApplicationService.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using Abp.Application.Features;
  4. using Abp.Authorization;
  5. using Abp.Runtime.Session;
  6. namespace Abp.Application.Services
  7. {
  8. /// <summary>
  9. /// This class can be used as a base class for application services.
  10. /// </summary>
  11. public abstract class ApplicationService : AbpServiceBase, IApplicationService, IAvoidDuplicateCrossCuttingConcerns
  12. {
  13. public static string[] CommonPostfixes = { "AppService", "ApplicationService" };
  14. /// <summary>
  15. /// Gets current session information.
  16. /// </summary>
  17. public IAbpSession AbpSession { get; set; }
  18. /// <summary>
  19. /// Reference to the permission manager.
  20. /// </summary>
  21. public IPermissionManager PermissionManager { protected get; set; }
  22. /// <summary>
  23. /// Reference to the permission checker.
  24. /// </summary>
  25. public IPermissionChecker PermissionChecker { protected get; set; }
  26. /// <summary>
  27. /// Reference to the feature manager.
  28. /// </summary>
  29. public IFeatureManager FeatureManager { protected get; set; }
  30. /// <summary>
  31. /// Reference to the feature checker.
  32. /// </summary>
  33. public IFeatureChecker FeatureChecker { protected get; set; }
  34. /// <summary>
  35. /// Gets the applied cross cutting concerns.
  36. /// </summary>
  37. public List<string> AppliedCrossCuttingConcerns { get; } = new List<string>();
  38. /// <summary>
  39. /// Constructor.
  40. /// </summary>
  41. protected ApplicationService()
  42. {
  43. AbpSession = NullAbpSession.Instance;
  44. PermissionChecker = NullPermissionChecker.Instance;
  45. }
  46. /// <summary>
  47. /// Checks if current user is granted for a permission.
  48. /// </summary>
  49. /// <param name="permissionName">Name of the permission</param>
  50. protected virtual Task<bool> IsGrantedAsync(string permissionName)
  51. {
  52. return PermissionChecker.IsGrantedAsync(permissionName);
  53. }
  54. /// <summary>
  55. /// Checks if current user is granted for a permission.
  56. /// </summary>
  57. /// <param name="permissionName">Name of the permission</param>
  58. protected virtual bool IsGranted(string permissionName)
  59. {
  60. return PermissionChecker.IsGranted(permissionName);
  61. }
  62. /// <summary>
  63. /// Checks if given feature is enabled for current tenant.
  64. /// </summary>
  65. /// <param name="featureName">Name of the feature</param>
  66. /// <returns></returns>
  67. protected virtual Task<bool> IsEnabledAsync(string featureName)
  68. {
  69. return FeatureChecker.IsEnabledAsync(featureName);
  70. }
  71. /// <summary>
  72. /// Checks if given feature is enabled for current tenant.
  73. /// </summary>
  74. /// <param name="featureName">Name of the feature</param>
  75. /// <returns></returns>
  76. protected virtual bool IsEnabled(string featureName)
  77. {
  78. return FeatureChecker.IsEnabled(featureName);
  79. }
  80. }
  81. }