Files
Umbraco-CMS/src/Umbraco.Core/Persistence/DatabaseFactory.cs
Morten@Thinkpad-X220 660ecfa91b Refactoring Unit Of Work, adding TransactionTypes and a new Repository structure.
Adding new Factory structure.
Related to U4-973, U4-955 and U4-979
2012-10-08 08:42:57 -02:00

47 lines
1.3 KiB
C#

using System.Threading;
using Umbraco.Core.Configuration;
namespace Umbraco.Core.Persistence
{
/// <summary>
/// Provides access to the PetaPoco database as Singleton, so the database is created once in app lifecycle.
/// This is necessary for transactions to work properly
/// </summary>
public sealed class DatabaseFactory
{
#region Singleton
private static Database _database;
private static volatile DatabaseFactory _instance;
private static readonly ReaderWriterLockSlim Lock = new ReaderWriterLockSlim();
private DatabaseFactory() { }
public static DatabaseFactory Current
{
get
{
using (new WriteLock(Lock))
{
if (_instance == null)
{
_instance = new DatabaseFactory();
_database = new Database(GlobalSettings.DbDsn);
}
}
return _instance;
}
}
#endregion
/// <summary>
/// Returns an instance of the PetaPoco database
/// </summary>
public Database Database
{
get { return _database; }
}
}
}