#Problem
UnitOfWork has a dependency upon IDataContextAsync. If this dependency is injected _in request scope_, and we begin a transaction, then we'll obtain an ObjectDisposedException in [UnitOfWork.cs](https://genericunitofworkandrepositories.codeplex.com/SourceControl/latest#main/Source/Repository.Pattern.Ef6/UnitOfWork.cs) line 41 when the UnitOfWork is disposed.
This is because _objectContext member is not null but it is already disposed by the time we check its Connection property.
#UnitOfWork.cs
```
public void Dispose()
{
if (_objectContext != null && objectContext.Connection.State == ConnectionState.Open)
{
_objectContext.Connection.Close();
}
Dispose(true);
GC.SuppressFinalize(this);
}
```
#One Possible Solution
Check whether _dataContext is disposed before access any of its properties.
```
public void Dispose()
{
if (!_dataContext.IsDisposed && _objectContext != null && _objectContext.Connection.State == ConnectionState.Open)
_objectContext.Connection.Close();
Dispose(true);
GC.SuppressFinalize(this);
}
```
```
public interface IDataContext : IDisposable
{
int SaveChanges();
void SyncObjectState(object entity);
bool IsDisposed { get; }
}
```
```
public class DataContext : DbContext, IDataContext, IDataContextAsync
{
private bool _isDisposed = false;
bool IsDisposed
{
get
{
return _isDisposed;
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_isDisposed = true;
}
}
```
Comments: Will be in the next release.