public DbContextScopeFactory(IAmbientDbContextFactory ambientDbContextFactory, ILoggerFactory loggerFactory, IScopeDiagnostic scopeDiagnostic = null)
 {
     _ambientDbContextFactory = ambientDbContextFactory;
     _loggerFactory           = loggerFactory;
     _scopeDiagnostic         = scopeDiagnostic;
     _logger = loggerFactory.CreateLogger <DbContextScopeFactory>();
 }
Esempio n. 2
0
 /// <summary>
 /// basic ctor
 /// </summary>
 /// <param name="factory">the ambient context factory</param>
 /// <param name="repository">the comment repository</param>
 /// <param name="validators">the comment validator</param>
 public CommentService(
     IAmbientDbContextFactory factory,
     ICommentRepository repository,
     ICommentValidators validators)
     : base(factory)
 {
     _repository = repository;
     _validators = validators;
 }
 /// <summary>
 /// basic ctor
 /// </summary>
 /// <param name="factory">the ambient context factory</param>
 /// <param name="repository">the person repository</param>
 /// <param name="validators">the person validator</param>
 public PersonService(
     IAmbientDbContextFactory factory,
     IPersonRepository repository,
     IPersonValidators validators)
     : base(factory)
 {
     _repository = repository;
     _validators = validators;
 }
Esempio n. 4
0
 public App(
     IAmbientDbContextFactory ambientContextFactory,
     AnUpdateQuery anUpdateQuery,
     AnInsertQuery anInsertQuery)
 {
     _ambientContextFactory = ambientContextFactory;
     _anUpdateQuery         = anUpdateQuery;
     _anInsertQuery         = anInsertQuery;
 }
Esempio n. 5
0
 /// <summary>
 /// basic ctor
 /// </summary>
 /// <param name="factory">the ambient context factory, used to create a db connection and context</param>
 /// <param name="repository">the activity repository</param>
 /// <param name="validators">the activity validator</param>
 public ActivityService(
     IAmbientDbContextFactory factory,
     IActivityRepository repository,
     IActivityValidators validators)
     : base(factory)
 {
     _repository = repository;
     _validators = validators;
 }
Esempio n. 6
0
        /// <summary>
        /// the basic ctor
        /// </summary>
        /// <param name="factory">the ambient context factory</param>
        protected BaseService(
            IAmbientDbContextFactory factory
            )
        {
            AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage());
            ContextFactory = factory;

            ContextFactory.Create();
        }
 public ValuesController(
     IAmbientDbContextFactory ambientContextFactory,
     AnUpdateQuery anUpdateQuery,
     AnInsertQuery anInsertQuery)
 {
     _ambientContextFactory = ambientContextFactory;
     _anUpdateQuery         = anUpdateQuery;
     _anInsertQuery         = anInsertQuery;
 }
        public DbContextCollection(bool readOnly = false, IsolationLevel?isolationLevel = null, IAmbientDbContextFactory dbContextFactory = null)
        {
            _disposed  = false;
            _completed = false;

            _initializedDbContexts = new Dictionary <Type, DbContext>();
            _transactions          = new Dictionary <DbContext, DbContextTransaction>();

            _readOnly         = readOnly;
            _isolationLevel   = isolationLevel;
            _dbContextFactory = dbContextFactory;
        }
        public DbContextCollection(DbContextScope dbContextScope, IAmbientDbContextFactory ambientDbContextFactory, ILoggerFactory loggerFactory, bool readOnly, IsolationLevel?isolationLevel)
        {
            _disposed  = false;
            _completed = false;
            _logger    = loggerFactory.CreateLogger <DbContextCollection>();

            InitializedDbContexts = new Dictionary <Type, (DbContext DbContext, IDbContextProxyBypass Proxy)>();
            _transactions         = new Dictionary <DbContext, IDbContextTransaction>();

            _dbContextScope          = dbContextScope;
            _readOnly                = readOnly;
            _isolationLevel          = isolationLevel;
            _ambientDbContextFactory = ambientDbContextFactory;
        }
Esempio n. 10
0
        public static void AssemblyInit(TestContext testContext)
        {

            Configuration = GetIConfigurationRoot(testContext.TestRunDirectory);

            AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage());

            ContextFactory = new AmbientDbContextFactory(new DbConnectionFactory(Configuration));

            ContextFactory.Create();

            ContextLocator = new AmbientDbContextLocator();

            DbContext = ContextLocator.Get();

        }
Esempio n. 11
0
 public DbContextReadOnlyScope(IsolationLevel isolationLevel, IAmbientDbContextFactory dbContextFactory = null)
     : this(joiningOption : DbContextScopeOption.ForceCreateNew, isolationLevel : isolationLevel, dbContextFactory : dbContextFactory)
 {
 }
 public DbContextReadOnlyScope(DbContextScopeOption joiningOption, IsolationLevel?isolationLevel, IAmbientDbContextFactory ambientDbContextFactory, ILoggerFactory loggerFactory, IScopeDiagnostic scopeDiagnostic)
 {
     _internalScope = new DbContextScope(joiningOption, true, isolationLevel, ambientDbContextFactory, loggerFactory, scopeDiagnostic);
 }
 public TransactionNotificationHandlerDecorator(IAmbientDbContextFactory ambientDbContextFactory, INotificationHandler <TNotification> decorated)
 {
     _ambientDbContextFactory = ambientDbContextFactory;
     _decorated = decorated;
 }
Esempio n. 14
0
 public DefaultUnitOfWorkManagement(IAmbientDbContextFactory ambientDbContextFactory)
 {
     _ambientDbContextFactory = ambientDbContextFactory;
 }
Esempio n. 15
0
        public DbContextScope(DbContextScopeOption joiningOption, bool readOnly, IsolationLevel?isolationLevel, IAmbientDbContextFactory ambientDbContextFactory, ILoggerFactory loggerFactory, IScopeDiagnostic scopeDiagnostic)
        {
            if (isolationLevel.HasValue && joiningOption == DbContextScopeOption.JoinExisting)
            {
                throw new ArgumentException("Cannot join an ambient DbContextScope when an explicit database transaction "
                                            + "is required. When requiring explicit database transactions to be used (i.e. when the "
                                            + "'isolationLevel' parameter is set), you must not also ask to join the ambient context "
                                            + "(i.e. the 'joinAmbient' parameter must be set to false).");
            }

            _disposed        = false;
            _completed       = false;
            _readOnly        = readOnly;
            _scopeDiagnostic = scopeDiagnostic;
            _logger          = loggerFactory.CreateLogger <DbContextScope>();

            _parentScope = AmbientContextScopeMagic.GetAmbientScope();
            if (_parentScope != null && joiningOption == DbContextScopeOption.JoinExisting)
            {
                if (_parentScope._readOnly && !_readOnly)
                {
                    throw new InvalidOperationException("Cannot nest a read/write DbContextScope within a read-only DbContextScope.");
                }

                _nested     = true;
                _dbContexts = _parentScope._dbContexts;
            }
            else
            {
                _nested     = false;
                _dbContexts = new DbContextCollection(this, ambientDbContextFactory, loggerFactory, readOnly, isolationLevel);
            }

            AmbientContextScopeMagic.SetAmbientScope(this);
        }
Esempio n. 16
0
 public DbContextScope(DbContextScopeOption joiningOption, IsolationLevel?isolationLevel, IAmbientDbContextFactory ambientDbContextFactory, ILoggerFactory loggerFactory, IScopeDiagnostic scopeDiagnostic)
     : base(joiningOption, false, isolationLevel, ambientDbContextFactory, loggerFactory, scopeDiagnostic)
 {
     _scopeDiagnostic = scopeDiagnostic;
 }
Esempio n. 17
0
 public DapperRepository(IAmbientDbContextLocator ambientDbContextLocator, IAmbientDbContextFactory ambientDbContextFactory)
 {
     _ambientDbContextLocator = ambientDbContextLocator;
     _ambientDbContextFactory = ambientDbContextFactory;
 }
Esempio n. 18
0
 public DbContextReadOnlyScope(DbContextScopeOption joiningOption, IsolationLevel?isolationLevel, IAmbientDbContextFactory dbContextFactory = null)
 {
     _internalScope = new DbContextScope(joiningOption : joiningOption, readOnly : true, isolationLevel : isolationLevel, dbContextFactory : dbContextFactory);
 }
 public DbContextScopeFactory(IAmbientDbContextFactory dbContextFactory = null)
 {
     _dbContextFactory = dbContextFactory;
 }
Esempio n. 20
0
 public DbContextReadOnlyScope(IAmbientDbContextFactory dbContextFactory = null)
     : this(joiningOption : DbContextScopeOption.JoinExisting, isolationLevel : null, dbContextFactory : dbContextFactory)
 {
 }
Esempio n. 21
0
        public DbContextScope(DbContextScopeOption joiningOption, bool readOnly, IsolationLevel?isolationLevel, IAmbientDbContextFactory dbContextFactory = null)
        {
            if (isolationLevel.HasValue && joiningOption == DbContextScopeOption.JoinExisting)
            {
                throw new ArgumentException("Cannot join an ambient DbContextScope when an explicit database transaction is required. When requiring explicit database transactions to be used (i.e. when the 'isolationLevel' parameter is set), you must not also ask to join the ambient context (i.e. the 'joinAmbient' parameter must be set to false).");
            }

            _disposed  = false;
            _completed = false;
            _readOnly  = readOnly;

            _parentScope = GetAmbientScope();
            if (_parentScope != null && joiningOption == DbContextScopeOption.JoinExisting)
            {
                if (_parentScope._readOnly && !this._readOnly)
                {
                    throw new InvalidOperationException("Cannot nest a read/write DbContextScope within a read-only DbContextScope.");
                }

                _nested     = true;
                _dbContexts = _parentScope._dbContexts;
            }
            else
            {
                _nested     = false;
                _dbContexts = new DbContextCollection(readOnly, isolationLevel, dbContextFactory);
            }

            SetAmbientScope(this);
        }