IActiveUnitOfWork.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using Abp.Domain.Entities;
  5. namespace Abp.Domain.Uow
  6. {
  7. /// <summary>
  8. /// This interface is used to work with active unit of work.
  9. /// This interface can not be injected.
  10. /// Use <see cref="IUnitOfWorkManager"/> instead.
  11. /// </summary>
  12. public interface IActiveUnitOfWork
  13. {
  14. /// <summary>
  15. /// This event is raised when this UOW is successfully completed.
  16. /// </summary>
  17. event EventHandler Completed;
  18. /// <summary>
  19. /// This event is raised when this UOW is failed.
  20. /// </summary>
  21. event EventHandler<UnitOfWorkFailedEventArgs> Failed;
  22. /// <summary>
  23. /// This event is raised when this UOW is disposed.
  24. /// </summary>
  25. event EventHandler Disposed;
  26. /// <summary>
  27. /// Gets if this unit of work is transactional.
  28. /// </summary>
  29. UnitOfWorkOptions Options { get; }
  30. /// <summary>
  31. /// Gets data filter configurations for this unit of work.
  32. /// </summary>
  33. IReadOnlyList<DataFilterConfiguration> Filters { get; }
  34. /// <summary>
  35. /// A dictionary to use for custom operations on unitOfWork
  36. /// </summary>
  37. Dictionary<string, object> Items { get; set; }
  38. /// <summary>
  39. /// Is this UOW disposed?
  40. /// </summary>
  41. bool IsDisposed { get; }
  42. /// <summary>
  43. /// Saves all changes until now in this unit of work.
  44. /// This method may be called to apply changes whenever needed.
  45. /// Note that if this unit of work is transactional, saved changes are also rolled back if transaction is rolled back.
  46. /// No explicit call is needed to SaveChanges generally,
  47. /// since all changes saved at end of a unit of work automatically.
  48. /// </summary>
  49. void SaveChanges();
  50. /// <summary>
  51. /// Saves all changes until now in this unit of work.
  52. /// This method may be called to apply changes whenever needed.
  53. /// Note that if this unit of work is transactional, saved changes are also rolled back if transaction is rolled back.
  54. /// No explicit call is needed to SaveChanges generally,
  55. /// since all changes saved at end of a unit of work automatically.
  56. /// </summary>
  57. Task SaveChangesAsync();
  58. /// <summary>
  59. /// Disables one or more data filters.
  60. /// Does nothing for a filter if it's already disabled.
  61. /// Use this method in a using statement to re-enable filters if needed.
  62. /// </summary>
  63. /// <param name="filterNames">One or more filter names. <see cref="AbpDataFilters"/> for standard filters.</param>
  64. /// <returns>A <see cref="IDisposable"/> handle to take back the disable effect.</returns>
  65. IDisposable DisableFilter(params string[] filterNames);
  66. /// <summary>
  67. /// Enables one or more data filters.
  68. /// Does nothing for a filter if it's already enabled.
  69. /// Use this method in a using statement to re-disable filters if needed.
  70. /// </summary>
  71. /// <param name="filterNames">One or more filter names. <see cref="AbpDataFilters"/> for standard filters.</param>
  72. /// <returns>A <see cref="IDisposable"/> handle to take back the enable effect.</returns>
  73. IDisposable EnableFilter(params string[] filterNames);
  74. /// <summary>
  75. /// Checks if a filter is enabled or not.
  76. /// </summary>
  77. /// <param name="filterName">Name of the filter. <see cref="AbpDataFilters"/> for standard filters.</param>
  78. bool IsFilterEnabled(string filterName);
  79. /// <summary>
  80. /// Sets (overrides) value of a filter parameter.
  81. /// </summary>
  82. /// <param name="filterName">Name of the filter</param>
  83. /// <param name="parameterName">Parameter's name</param>
  84. /// <param name="value">Value of the parameter to be set</param>
  85. IDisposable SetFilterParameter(string filterName, string parameterName, object value);
  86. /// <summary>
  87. /// Sets/Changes Tenant's Id for this UOW.
  88. /// </summary>
  89. /// <param name="tenantId">The tenant id.</param>
  90. /// <returns>A disposable object to restore old TenantId value when you dispose it</returns>
  91. IDisposable SetTenantId(int? tenantId);
  92. /// <summary>
  93. /// Sets/Changes Tenant's Id for this UOW.
  94. /// </summary>
  95. /// <param name="tenantId">The tenant id</param>
  96. /// <param name="switchMustHaveTenantEnableDisable">
  97. /// True to enable/disable <see cref="IMustHaveTenant"/> based on given tenantId.
  98. /// Enables <see cref="IMustHaveTenant"/> filter if tenantId is not null.
  99. /// Disables <see cref="IMustHaveTenant"/> filter if tenantId is null.
  100. /// This value is true for <see cref="SetTenantId(int?)"/> method.
  101. /// </param>
  102. /// <returns>A disposable object to restore old TenantId value when you dispose it</returns>
  103. IDisposable SetTenantId(int? tenantId, bool switchMustHaveTenantEnableDisable);
  104. /// <summary>
  105. /// Gets Tenant Id for this UOW.
  106. /// </summary>
  107. /// <returns></returns>
  108. int? GetTenantId();
  109. }
  110. }