/// <summary> /// Dispose unmanaged resources and/or set large fields /// (managed/unmanaged) to null. This method will be called whether /// the <see cref="Disposable.Dispose()"/> method is called by the /// finalizer or your code. /// </summary> protected override void DisposeExtra() { base.DisposeExtra(); _storageContext = null; _configuration = null; _queryBuilder = null; _cmdBuilder = null; _entityBuilder = null; }
/// <summary> /// Initialize a new instance of the class with the unit of work reference. /// </summary> /// <param name="unitOfWork">Unit of work reference to be used.</param> public DbRepository(IUnitOfWork unitOfWork) : base(unitOfWork) { _storageContext = this.UnitOfWork.StorageContext as DbStorageContext; if (_storageContext == null) { throw new InvalidCastException("Wrong storage context"); } _configuration = _storageContext.GetEntityConfiguration <TEntity>(); if (_configuration == null) { throw new NullReferenceException("Entity configuration null"); } DbRepositoryComponentFactory factory = GetComponentFactory(); _queryBuilder = (TQueryBuilder)factory.CreateQueryBuilder <TEntity, TQueryBuilder>(_storageContext); _cmdBuilder = factory.CreateCommandBuilder <TEntity>(_queryBuilder, _storageContext); _entityBuilder = factory.CreateEntityBuilder <TEntity>(_storageContext); }