1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/Marr.Data/UnitOfWorkSharedContext.cs
2013-07-18 20:47:55 -07:00

39 lines
858 B
C#

using System;
namespace Marr.Data
{
/// <summary>
/// Works in conjunction with the UnitOfWork to create a new
/// shared context that will preserve a single IDataMapper.
/// </summary>
public class UnitOfWorkSharedContext : IDisposable
{
private UnitOfWork _mgr;
private bool _isParentContext;
public UnitOfWorkSharedContext(UnitOfWork mgr)
{
_mgr = mgr;
if (_mgr.IsShared)
{
_isParentContext = false;
}
else
{
_isParentContext = true;
_mgr.IsShared = true;
}
}
public void Dispose()
{
if (_isParentContext)
{
_mgr.IsShared = false;
_mgr.Dispose();
}
}
}
}