Exemple #1
0
        /// <summary>
        /// Overloaded Constructor.
        /// Creates a new instance of the <see cref="UnitOfWorkScope"/> class.
        /// </summary>
        /// <param name="mode">A <see cref="TransactionMode"/> enum specifying the transation mode
        /// of the unit of work.</param>
        public UnityUnitOfWorkScope(IUnityUnitOfWorkManager manager, TransactionMode mode, CustomUnitOfWorkSettings settings)
        {
            //Guard.Against<ArgumentNullException>(container == null, "Ошибка создания UnityUnitOfWorkScope: не определен Unity-контейнер");
            Guard.Against <ArgumentNullException>(settings == null, "Ошибка создания UnityUnitOfWorkScope: не определены Settings");

            _manager = manager;
            //Container = container;
            _autoCompleteScope = settings.AutoCompleteScope;
            //UnitOfWorkManager.CurrentTransactionManager.EnlistScope(this, mode);
            //Container.Resolve<ITransactionManager>().EnlistScope(this, mode);
            _manager.CurrentTransactionManager().EnlistScope(this, mode);
        }
Exemple #2
0
        /// <summary>
        /// Gets the current unit of work that the scope participates in.
        /// </summary>
        /// <typeparam name="T">The type of <see cref="IUnitOfWork"/> to retrieve.</typeparam>
        /// <returns>A <see cref="IUnitOfWork"/> instance of type <typeparamref name="T"/> that
        /// the scope participates in.</returns>
        public T CurrentUnitOfWork <T>()
        {
            //var currentUow = UnitOfWorkManager.CurrentUnitOfWork;
            //var currentUow = Container.Resolve<ITransactionManager>().CurrentUnitOfWork;
            var currentUow = _manager.CurrentTransactionManager().CurrentUnitOfWork;

            Guard.Against <InvalidOperationException>(currentUow == null,
                                                      "No compatible UnitOfWork was found. Please start a compatible UnitOfWorkScope before " +
                                                      "using the repository.");

            Guard.TypeOf <T>(currentUow,
                             "The current unit of work is not compatible with expected type" + typeof(T).FullName +
                             ", instead the current unit of work is of type " + currentUow.GetType().FullName + ".");
            return((T)currentUow);
        }