Beispiel #1
0
        /** <summary>
         Set UnitOfWork settings that will be used by default.
         For example, to disable commits or to rollback transaction on UnitOfWork completion(could be useful when writing Integration tests)
           </summary>*/
        public static IAntlerConfigurator SetUnitOfWorkDefaultSettings(this IAntlerConfigurator configurator,
                                                                 UnitOfWorkSettings settings)
        {
            Requires.NotNull(settings, "settings");

            UnitOfWorkSettings.Default = settings;
            return configurator;
        }
Beispiel #2
0
        /// <summary>
        /// Start database transaction and return result from it.
        /// </summary>
        public static TResult Do <TResult>(Func <UnitOfWork, TResult> work, UnitOfWorkSettings settings = null)
        {
            Requires.NotNull(work, "work");

            using (var uow = new UnitOfWork(settings))
            {
                return(work(uow));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Start database transaction.
        /// </summary>
        public static void Do(Action <UnitOfWork> work, UnitOfWorkSettings settings = null)
        {
            Requires.NotNull(work, "work");

            using (var uow = new UnitOfWork(settings))
            {
                work(uow);
            }
        }
Beispiel #4
0
        private UnitOfWork(UnitOfWorkSettings settings)
        {
            Settings = settings ?? UnitOfWorkSettings.Default;

            Assumes.True(SessionScopeFactoryExtractor != null, "SessionScopeFactoryExtractor should be set before using UnitOfWork. Wrong configuraiton?");
            Assumes.True(!string.IsNullOrEmpty(Settings.StorageName), "Storage name can't be null or empty. Wrong configuration?");
            var sessionScopeFactory = SessionScopeFactoryExtractor(Settings.StorageName);

            Assumes.True(sessionScopeFactory != null, "Can't find storage with name {0}. Wrong storage name?", Settings.StorageName);
            SetSession(sessionScopeFactory);
        }
Beispiel #5
0
        /// <summary>
        /// Start database transaction and return result from it(asynchronous version).
        /// </summary>
        public static Task <TResult> DoAsync <TResult>(Func <UnitOfWork, TResult> work, UnitOfWorkSettings settings = null)
        {
            Requires.NotNull(work, "work");

            return(Task <TResult> .Factory.StartNew(() => Do(work, settings)));
        }
Beispiel #6
0
        /// <summary>
        /// Start database transaction(asynchronous version).
        /// </summary>
        public static Task DoAsync(Action <UnitOfWork> work, UnitOfWorkSettings settings = null)
        {
            Requires.NotNull(work, "work");

            return(Task.Factory.StartNew(() => Do(work, settings)));
        }
Beispiel #7
0
            public void should_throw()
            {
                //act
                var setting = new UnitOfWorkSettings() {ThrowIfNestedUnitOfWork = true};

                UnitOfWork.Do(uow => UnitOfWork.Do(nested => nested, setting), setting);
            }