Fixes ServiceContext to ensure the repo's are lazy instantiated because their ctor's rely on the
RepositoryResolver.Current being initialized which normally doesn't occur until after the ServiceContext is constructed. Adds instance level caching for the GetRecursiveValue method in case this is called more than one time for a property in one view. Reverts PetaPocoUnitOfWork to allow more than one call to Commit().. this isn't 'best practices' per se but it is more for performance reasons because otherwise we'd have to create a new repo object + uow for any bulk saving operations... The end result is the same, bulk operations in the Services cannot be processed in one transaction. Fixing up the ContentServiceTests by ensuring that the shared and always open sqlce connection with the legacy SqlCeContextGuardian is closed on TearDown.
This commit is contained in:
@@ -11,7 +11,7 @@ namespace SQLCE4Umbraco
|
||||
public static class SqlCeContextGuardian
|
||||
{
|
||||
private static SqlCeConnection _constantOpenConnection;
|
||||
private static object objLock = new object();
|
||||
private static readonly object Lock = new object();
|
||||
|
||||
// Awesome SQL CE 4 speed improvement by Erik Ejskov Jensen - SQL CE 4 MVP
|
||||
// It's not an issue with SQL CE 4 that we never close the connection
|
||||
@@ -29,7 +29,7 @@ namespace SQLCE4Umbraco
|
||||
connectionStringBuilder.Remove("datalayer");
|
||||
|
||||
// SQL CE 4 performs better when there's always a connection open in the background
|
||||
ensureOpenBackgroundConnection(connectionStringBuilder.ConnectionString);
|
||||
EnsureOpenBackgroundConnection(connectionStringBuilder.ConnectionString);
|
||||
|
||||
SqlCeConnection conn = new SqlCeConnection(connectionStringBuilder.ConnectionString);
|
||||
conn.Open();
|
||||
@@ -38,9 +38,18 @@ namespace SQLCE4Umbraco
|
||||
|
||||
}
|
||||
|
||||
private static void ensureOpenBackgroundConnection(string connectionString)
|
||||
/// <summary>
|
||||
/// Sometimes we need to ensure this is closed especially in unit tests
|
||||
/// </summary>
|
||||
internal static void CloseBackgroundConnection()
|
||||
{
|
||||
if (_constantOpenConnection != null)
|
||||
_constantOpenConnection.Close();
|
||||
}
|
||||
|
||||
private static void EnsureOpenBackgroundConnection(string connectionString)
|
||||
{
|
||||
lock (objLock)
|
||||
lock (Lock)
|
||||
{
|
||||
if (_constantOpenConnection == null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user