protected override void Dispose(bool explicitDispose) { if (explicitDispose) { _dataContextPool?.Dispose(); _referenceKeyProvider?.Dispose(); } _dataContextPool = null; _dataContextPoolingSettings = null; _efDbContextOptions = null; _referenceKeyProviderSettings = null; _referenceKeyProvider = null; _serviceProvider = null; // base.Dispose(explicitDispose); }
// 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; }
public PoolingSettings(IPoolingSettings other, bool isReadOnly = default) : this(poolDisplayName : other.EnsureNotNull(nameof(other)).Value.PoolDisplayName, isDisabled : other.IsDisabled, poolSize : other.PoolSize, preferredSlidingTtl : other.PreferredSlidingTtl, isReadOnly : isReadOnly) { }