public EfCoreDbContextCtorArgs(DbContextOptions options, bool isReadOnly, ILogger logger) { options.EnsureNotNull(nameof(options)); // Options = options; IsReadOnly = isReadOnly; Logger = logger; }
public PersistenceEfCoreDataContext(IPersistenceDataContextProvider <IPersistenceDataContext <TEfDbContext> > provider, DbContextOptions <TEfDbContext> efDbContextOptions, ILogger logger) : base(outerDependencies: provider.EnsureNotNull(nameof(provider)).Value) { efDbContextOptions.EnsureNotNull(nameof(efDbContextOptions)); if (!efDbContextOptions.IsFrozen) { throw new ArgumentException( message: $"EF context options must be frozen (see {nameof(DbContextOptions)}.{nameof(DbContextOptions.IsFrozen)}) before using by this component.{Environment.NewLine}\tComponent:{this.FmtStr().GNLI2()}", paramName: nameof(efDbContextOptions)); } // _provider = provider; _efDbContextOptions = efDbContextOptions; _initializationLock = new SemaphoreSlim(initialCount: 1, maxCount: 1); _isInitialized = false; _efCtxLazy = new DisposableLazy <TEfDbContext>(factory: () => P_CreateAndAdjustEfDbContext(isReadOnly: false), ownsValue: true); _logger = logger; _txScopes = ImmutableStack <PersistenceEfCoreDataContextTxScope> .Empty; }
// TODO: Put strings into the resources. // public PersistenceEfCoreDataContextProvider(IServiceProvider outerServiceProvider, DbContextOptions <TEfDbContext> efDbContextOptions, IPoolingSettings pooling = default, IReferenceKeyProviderSettings referenceKeyProvider = default) : base(outerServiceProvider: outerServiceProvider.EnsureNotNull(nameof(outerServiceProvider)).Value) { efDbContextOptions.EnsureNotNull(nameof(efDbContextOptions)); if (!efDbContextOptions.IsFrozen) { throw new ArgumentException( message: $"EF context options must be frozen (see {nameof(DbContextOptions)}.{nameof(DbContextOptions.IsFrozen)}) before using by this component.{Environment.NewLine}\tComponent:{this.FmtStr().GNLI2()}", paramName: nameof(efDbContextOptions)); } pooling.Arg(nameof(pooling)).EnsureReadOnly().EnsureValid(); referenceKeyProvider.Arg(nameof(referenceKeyProvider)).EnsureReadOnly().EnsureValid(); // _serviceProvider = outerServiceProvider; _efDbContextOptions = efDbContextOptions; _dataContextPoolingSettings = pooling; _isDataContextPoolingEnabled = !(pooling?.IsDisabled ?? true); if (_isDataContextPoolingEnabled) { _dataContextPool = new Pool <IPersistenceDataContext <TEfDbContext> >( itemFactory: CreateContextAsync, ownsItem: true, itemPreferredSlidingTtl: pooling.PreferredSlidingTtl, maxSize: pooling.PoolSize.Value, displayName: pooling.PoolDisplayName, logger: ((ILogger)outerServiceProvider.GetService(serviceType: typeof(ILogger <TEfDbContext>))).ArgPlaceholder()); } else { _dataContextPool = null; } // _referenceKeyProviderSettings = referenceKeyProvider; }