From e5ec9eb06f856cf16d9bab8edef22aaf5422e5f2 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Mon, 26 Nov 2012 17:20:58 -0100 Subject: [PATCH] Reducing the usage of the DatabaseFactory --- src/Umbraco.Core/Auditing/DataAuditWriteProvider.cs | 2 +- src/Umbraco.Core/Persistence/DatabaseFactory.cs | 6 +++++- .../Persistence/Repositories/PetaPocoRepositoryBase.cs | 2 +- src/Umbraco.Core/Services/UserService.cs | 2 +- src/Umbraco.Tests/CodeFirst/Definitions/Conventions.cs | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Core/Auditing/DataAuditWriteProvider.cs b/src/Umbraco.Core/Auditing/DataAuditWriteProvider.cs index e29f6e93b8..2837eeff4f 100644 --- a/src/Umbraco.Core/Auditing/DataAuditWriteProvider.cs +++ b/src/Umbraco.Core/Auditing/DataAuditWriteProvider.cs @@ -16,7 +16,7 @@ namespace Umbraco.Core.Auditing /// Audit comment public void WriteEntry(int objectId, int userId, DateTime date, string header, string comment) { - DatabaseFactory.Current.Database.Insert(new LogDto + DatabaseContext.Current.Database.Insert(new LogDto { Comment = comment, Datestamp = date, diff --git a/src/Umbraco.Core/Persistence/DatabaseFactory.cs b/src/Umbraco.Core/Persistence/DatabaseFactory.cs index 1b166f5e55..52ce7c6cd3 100644 --- a/src/Umbraco.Core/Persistence/DatabaseFactory.cs +++ b/src/Umbraco.Core/Persistence/DatabaseFactory.cs @@ -6,8 +6,12 @@ namespace Umbraco.Core.Persistence { /// /// Provides access to the PetaPoco database as Singleton, so the database is created once in app lifetime. - /// This is necessary for transactions to work properly + /// This is necessary for transactions to work properly. /// + /// + /// Because the Database is created static, the configuration has to be checked and set in + /// another class, which is where the DatabaseContext comes in. + /// public sealed class DatabaseFactory { #region Singleton diff --git a/src/Umbraco.Core/Persistence/Repositories/PetaPocoRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/PetaPocoRepositoryBase.cs index 373c5fe327..a4a4526de0 100644 --- a/src/Umbraco.Core/Persistence/Repositories/PetaPocoRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/PetaPocoRepositoryBase.cs @@ -25,7 +25,7 @@ namespace Umbraco.Core.Persistence.Repositories protected Database Database { - get { return DatabaseFactory.Current.Database; } + get { return DatabaseContext.Current.Database; } } #region Abstract Methods diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index e7ae4ebb8d..4bd7360291 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -47,7 +47,7 @@ namespace Umbraco.Core.Services if(HttpRuntime.Cache[cacheKey] == null) { userId = - DatabaseFactory.Current.Database.ExecuteScalar( + DatabaseContext.Current.Database.ExecuteScalar( "select userID from umbracoUserLogins where contextID = @ContextId", new {ContextId = new Guid(contextId)}); diff --git a/src/Umbraco.Tests/CodeFirst/Definitions/Conventions.cs b/src/Umbraco.Tests/CodeFirst/Definitions/Conventions.cs index 6173c30213..5755b38b2b 100644 --- a/src/Umbraco.Tests/CodeFirst/Definitions/Conventions.cs +++ b/src/Umbraco.Tests/CodeFirst/Definitions/Conventions.cs @@ -112,7 +112,7 @@ namespace Umbraco.Tests.CodeFirst.Definitions Value = value }; - DatabaseFactory.Current.Database.Insert(poco); + DatabaseContext.Current.Database.Insert(poco); } ///