UnitOfWorkOptions.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Transactions;
  5. namespace Abp.Domain.Uow
  6. {
  7. /// <summary>
  8. /// Unit of work options.
  9. /// </summary>
  10. public class UnitOfWorkOptions
  11. {
  12. /// <summary>
  13. /// Scope option.
  14. /// </summary>
  15. public TransactionScopeOption? Scope { get; set; }
  16. /// <summary>
  17. /// Is this UOW transactional?
  18. /// Uses default value if not supplied.
  19. /// </summary>
  20. public bool? IsTransactional { get; set; }
  21. /// <summary>
  22. /// Timeout of UOW As milliseconds.
  23. /// Uses default value if not supplied.
  24. /// </summary>
  25. public TimeSpan? Timeout { get; set; }
  26. /// <summary>
  27. /// If this UOW is transactional, this option indicated the isolation level of the transaction.
  28. /// Uses default value if not supplied.
  29. /// </summary>
  30. public IsolationLevel? IsolationLevel { get; set; }
  31. /// <summary>
  32. /// This option should be set to <see cref="TransactionScopeAsyncFlowOption.Enabled"/>
  33. /// if unit of work is used in an async scope.
  34. /// </summary>
  35. public TransactionScopeAsyncFlowOption? AsyncFlowOption { get; set; }
  36. /// <summary>
  37. /// Can be used to enable/disable some filters.
  38. /// </summary>
  39. public List<DataFilterConfiguration> FilterOverrides { get; }
  40. /// <summary>
  41. /// Creates a new <see cref="UnitOfWorkOptions"/> object.
  42. /// </summary>
  43. public UnitOfWorkOptions()
  44. {
  45. FilterOverrides = new List<DataFilterConfiguration>();
  46. }
  47. internal void FillDefaultsForNonProvidedOptions(IUnitOfWorkDefaultOptions defaultOptions)
  48. {
  49. //TODO: Do not change options object..?
  50. if (!IsTransactional.HasValue)
  51. {
  52. IsTransactional = defaultOptions.IsTransactional;
  53. }
  54. if (!Scope.HasValue)
  55. {
  56. Scope = defaultOptions.Scope;
  57. }
  58. if (!Timeout.HasValue && defaultOptions.Timeout.HasValue)
  59. {
  60. Timeout = defaultOptions.Timeout.Value;
  61. }
  62. if (!IsolationLevel.HasValue && defaultOptions.IsolationLevel.HasValue)
  63. {
  64. IsolationLevel = defaultOptions.IsolationLevel.Value;
  65. }
  66. }
  67. internal void FillOuterUowFiltersForNonProvidedOptions(List<DataFilterConfiguration> filterOverrides)
  68. {
  69. foreach (var filterOverride in filterOverrides)
  70. {
  71. if (FilterOverrides.Any(fo => fo.FilterName == filterOverride.FilterName))
  72. {
  73. continue;
  74. }
  75. FilterOverrides.Add(filterOverride);
  76. }
  77. }
  78. }
  79. }