diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowActionFilter.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowActionFilter.cs index 5996724a20..5b005facee 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowActionFilter.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowActionFilter.cs @@ -32,7 +32,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Uow return; } - var options = new UnitOfWorkStartOptions(); + var options = new UnitOfWorkOptions(); unitOfWorkAttr?.SetOptions(options); diff --git a/src/Volo.Abp/Volo/Abp/Uow/ChildUnitOfWork.cs b/src/Volo.Abp/Volo/Abp/Uow/ChildUnitOfWork.cs index 3683bbd7c4..3c054bbd5d 100644 --- a/src/Volo.Abp/Volo/Abp/Uow/ChildUnitOfWork.cs +++ b/src/Volo.Abp/Volo/Abp/Uow/ChildUnitOfWork.cs @@ -9,7 +9,7 @@ namespace Volo.Abp.Uow { public Guid Id => _parent.Id; - public IUnitOfWorkStartOptions Options => _parent.Options; + public IUnitOfWorkOptions Options => _parent.Options; public IUnitOfWork Outer => _parent.Outer; @@ -30,9 +30,9 @@ namespace Volo.Abp.Uow _parent.SetOuter(outer); } - public void SetOptions(UnitOfWorkStartOptions options) + public void Initialize(UnitOfWorkOptions options) { - _parent.SetOptions(options); + _parent.Initialize(options); } public event EventHandler Completed; diff --git a/src/Volo.Abp/Volo/Abp/Uow/IUnitOfWork.cs b/src/Volo.Abp/Volo/Abp/Uow/IUnitOfWork.cs index ba47e431d2..acee44e91d 100644 --- a/src/Volo.Abp/Volo/Abp/Uow/IUnitOfWork.cs +++ b/src/Volo.Abp/Volo/Abp/Uow/IUnitOfWork.cs @@ -4,7 +4,7 @@ namespace Volo.Abp.Uow { public interface IUnitOfWork : IBasicUnitOfWork, IDatabaseApiContainer, ITransactionApiContainer { - IUnitOfWorkStartOptions Options { get; } + IUnitOfWorkOptions Options { get; } IUnitOfWork Outer { get; } @@ -14,6 +14,6 @@ namespace Volo.Abp.Uow void SetOuter([CanBeNull] IUnitOfWork outer); - void SetOptions(UnitOfWorkStartOptions options); + void Initialize([NotNull] UnitOfWorkOptions options); } } diff --git a/src/Volo.Abp/Volo/Abp/Uow/IUnitOfWorkManager.cs b/src/Volo.Abp/Volo/Abp/Uow/IUnitOfWorkManager.cs index 1fc871dd3e..d1f8c534fb 100644 --- a/src/Volo.Abp/Volo/Abp/Uow/IUnitOfWorkManager.cs +++ b/src/Volo.Abp/Volo/Abp/Uow/IUnitOfWorkManager.cs @@ -8,13 +8,13 @@ namespace Volo.Abp.Uow IUnitOfWork Current { get; } [NotNull] - IBasicUnitOfWork Begin([NotNull] UnitOfWorkStartOptions options, bool requiresNew = false); + IBasicUnitOfWork Begin([NotNull] UnitOfWorkOptions options, bool requiresNew = false); [NotNull] IBasicUnitOfWork Reserve([NotNull] string reservationName, bool requiresNew = false); - void BeginReserved([NotNull] string reservationName, [NotNull] UnitOfWorkStartOptions options); + void BeginReserved([NotNull] string reservationName, [NotNull] UnitOfWorkOptions options); - bool TryBeginReserved([NotNull] string reservationName, [NotNull] UnitOfWorkStartOptions options); + bool TryBeginReserved([NotNull] string reservationName, [NotNull] UnitOfWorkOptions options); } } \ No newline at end of file diff --git a/src/Volo.Abp/Volo/Abp/Uow/IUnitOfWorkStartOptions.cs b/src/Volo.Abp/Volo/Abp/Uow/IUnitOfWorkOptions.cs similarity index 81% rename from src/Volo.Abp/Volo/Abp/Uow/IUnitOfWorkStartOptions.cs rename to src/Volo.Abp/Volo/Abp/Uow/IUnitOfWorkOptions.cs index 9fe3bc1084..b79b7112b8 100644 --- a/src/Volo.Abp/Volo/Abp/Uow/IUnitOfWorkStartOptions.cs +++ b/src/Volo.Abp/Volo/Abp/Uow/IUnitOfWorkOptions.cs @@ -3,7 +3,7 @@ using System.Data; namespace Volo.Abp.Uow { - public interface IUnitOfWorkStartOptions + public interface IUnitOfWorkOptions { bool IsTransactional { get; } diff --git a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWork.cs b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWork.cs index 810a94ec91..d6441ab01f 100644 --- a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWork.cs +++ b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWork.cs @@ -11,7 +11,7 @@ namespace Volo.Abp.Uow { public Guid Id { get; } = Guid.NewGuid(); - public IUnitOfWorkStartOptions Options { get; private set; } + public IUnitOfWorkOptions Options { get; private set; } public IUnitOfWork Outer { get; private set; } @@ -27,13 +27,13 @@ namespace Volo.Abp.Uow private readonly Dictionary _databaseApis; private readonly Dictionary _transactionApis; - private readonly UnitOfWorkOptions _defaultOptions; + private readonly UnitOfWorkDefaultOptions _defaultOptions; private Exception _exception; private bool _isCompleted; private bool _isDisposed; - public UnitOfWork(IServiceProvider serviceProvider, IOptions options) + public UnitOfWork(IServiceProvider serviceProvider, IOptions options) { ServiceProvider = serviceProvider; _defaultOptions = options.Value; @@ -42,11 +42,13 @@ namespace Volo.Abp.Uow _transactionApis = new Dictionary(); } - public void SetOptions(UnitOfWorkStartOptions options) + public void Initialize(UnitOfWorkOptions options) { + Check.NotNull(options, nameof(options)); + if (Options != null) { - throw new AbpException("Options must be set only once!"); + throw new AbpException("This unit of work is already initialized before!"); } Options = _defaultOptions.Normalize(options.Clone()); diff --git a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkAttribute.cs b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkAttribute.cs index 7c58fccfc0..351eefd859 100644 --- a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkAttribute.cs +++ b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkAttribute.cs @@ -37,7 +37,7 @@ namespace Volo.Abp.Uow /// public bool IsDisabled { get; set; } - public virtual void SetOptions(UnitOfWorkStartOptions options) + public virtual void SetOptions(UnitOfWorkOptions options) { if (IsTransactional.HasValue) { diff --git a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkDefaultOptions.cs b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkDefaultOptions.cs new file mode 100644 index 0000000000..7296eba767 --- /dev/null +++ b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkDefaultOptions.cs @@ -0,0 +1,34 @@ +using System; +using System.Data; + +namespace Volo.Abp.Uow +{ + //TODO: Implement default options! + + /// + /// Global (default) unit of work options + /// + public class UnitOfWorkDefaultOptions + { + public UnitOfWorkTransactionBehavior TransactionBehavior { get; set; } + + public IsolationLevel? IsolationLevel { get; set; } + + public TimeSpan? Timeout { get; set; } + + internal UnitOfWorkOptions Normalize(UnitOfWorkOptions options) + { + if (options.IsolationLevel == null) + { + options.IsolationLevel = IsolationLevel; + } + + if (options.Timeout == null) + { + options.Timeout = Timeout; + } + + return options; + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkManager.cs b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkManager.cs index 50bb080583..077481ffa1 100644 --- a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkManager.cs +++ b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkManager.cs @@ -19,7 +19,7 @@ namespace Volo.Abp.Uow _ambientUnitOfWork = ambientUnitOfWork; } - public IBasicUnitOfWork Begin(UnitOfWorkStartOptions options, bool requiresNew = false) + public IBasicUnitOfWork Begin(UnitOfWorkOptions options, bool requiresNew = false) { Check.NotNull(options, nameof(options)); @@ -29,7 +29,7 @@ namespace Volo.Abp.Uow } var unitOfWork = CreateNewUnitOfWork(); - unitOfWork.SetOptions(options); + unitOfWork.Initialize(options); return unitOfWork; } @@ -53,7 +53,7 @@ namespace Volo.Abp.Uow return unitOfWork; } - public void BeginReserved(string reservationName, UnitOfWorkStartOptions options) + public void BeginReserved(string reservationName, UnitOfWorkOptions options) { if (!TryBeginReserved(reservationName, options)) { @@ -61,7 +61,7 @@ namespace Volo.Abp.Uow } } - public bool TryBeginReserved(string reservationName, UnitOfWorkStartOptions options) + public bool TryBeginReserved(string reservationName, UnitOfWorkOptions options) { Check.NotNull(reservationName, nameof(reservationName)); @@ -79,7 +79,7 @@ namespace Volo.Abp.Uow } uow.IsReserved = false; - uow.SetOptions(options); + uow.Initialize(options); return true; } diff --git a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkManagerExtensions.cs b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkManagerExtensions.cs index 8e4aaae90d..3a9f949017 100644 --- a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkManagerExtensions.cs +++ b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkManagerExtensions.cs @@ -9,7 +9,7 @@ namespace Volo.Abp.Uow { Check.NotNull(unitOfWorkManager, nameof(unitOfWorkManager)); - return unitOfWorkManager.Begin(new UnitOfWorkStartOptions(), requiresNew); + return unitOfWorkManager.Begin(new UnitOfWorkOptions(), requiresNew); } public static void BeginReserved([NotNull] this IUnitOfWorkManager unitOfWorkManager, [NotNull] string reservationName) @@ -17,7 +17,7 @@ namespace Volo.Abp.Uow Check.NotNull(unitOfWorkManager, nameof(unitOfWorkManager)); Check.NotNull(reservationName, nameof(reservationName)); - unitOfWorkManager.BeginReserved(reservationName, new UnitOfWorkStartOptions()); + unitOfWorkManager.BeginReserved(reservationName, new UnitOfWorkOptions()); } public static void TryBeginReserved([NotNull] this IUnitOfWorkManager unitOfWorkManager, [NotNull] string reservationName) @@ -25,7 +25,7 @@ namespace Volo.Abp.Uow Check.NotNull(unitOfWorkManager, nameof(unitOfWorkManager)); Check.NotNull(reservationName, nameof(reservationName)); - unitOfWorkManager.TryBeginReserved(reservationName, new UnitOfWorkStartOptions()); + unitOfWorkManager.TryBeginReserved(reservationName, new UnitOfWorkOptions()); } } } \ No newline at end of file diff --git a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkOptions.cs b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkOptions.cs index c073c7ad6a..3d433f3738 100644 --- a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkOptions.cs +++ b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkOptions.cs @@ -3,32 +3,25 @@ using System.Data; namespace Volo.Abp.Uow { - //TODO: Implement default options! - - /// - /// Global (default) unit of work options - /// - public class UnitOfWorkOptions + public class UnitOfWorkOptions : IUnitOfWorkOptions { - public UnitOfWorkTransactionBehavior TransactionBehavior { get; set; } + /// + /// Default: false. + /// + public bool IsTransactional { get; set; } public IsolationLevel? IsolationLevel { get; set; } public TimeSpan? Timeout { get; set; } - internal UnitOfWorkStartOptions Normalize(UnitOfWorkStartOptions options) + public UnitOfWorkOptions Clone() { - if (options.IsolationLevel == null) + return new UnitOfWorkOptions { - options.IsolationLevel = IsolationLevel; - } - - if (options.Timeout == null) - { - options.Timeout = Timeout; - } - - return options; + IsTransactional = IsTransactional, + IsolationLevel = IsolationLevel, + Timeout = Timeout + }; } } } \ No newline at end of file diff --git a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkStartOptions.cs b/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkStartOptions.cs deleted file mode 100644 index ccde083786..0000000000 --- a/src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkStartOptions.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Data; - -namespace Volo.Abp.Uow -{ - public class UnitOfWorkStartOptions : IUnitOfWorkStartOptions - { - /// - /// Default: false. - /// - public bool IsTransactional { get; set; } - - public IsolationLevel? IsolationLevel { get; set; } - - public TimeSpan? Timeout { get; set; } - - public UnitOfWorkStartOptions Clone() - { - return new UnitOfWorkStartOptions - { - IsTransactional = IsTransactional, - IsolationLevel = IsolationLevel, - Timeout = Timeout - }; - } - } -} \ No newline at end of file