Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
DataMapper 3.0
-
None
-
None
Description
Move duplicate code for creating the local session into a class level scope that has access to the private members of DataMapper:
private class DataMapperLocalSessionScope : IDisposable
{
private readonly ISession session;
private readonly bool isSessionLocal = false;
public DataMapperLocalSessionScope(DataMapper dataMapper)
{
isSessionLocal = false;
session = dataMapper.sessionStore.CurrentSession;
if (session == null)
{ session = dataMapper.sessionFactory.OpenSession(); isSessionLocal = true; }}
public ISession Session
{
get
}
public void Dispose()
{
if (isSessionLocal)
}
}
to avoid duplicating code across 22 methods. The code in each of the Query... methods is now much shorter:
public IList QueryForList(string statementId, object parameterObject)
{
using (DataMapperLocalSessionScope sessionScope = new DataMapperLocalSessionScope(this))
}