More dependency cleanup, less singleton usages, better testing implementations
This commit is contained in:
@@ -8,51 +8,84 @@ using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Core.Persistence
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the Umbraco implementation of the PetaPoco Database object
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Currently this object exists for 'future proofing' our implementation. By having our own inheritied implementation we
|
||||
/// can then override any additional execution (such as additional loggging, functionality, etc...) that we need to without breaking compatibility since we'll always be exposing
|
||||
/// this object instead of the base PetaPoco database object.
|
||||
/// </remarks>
|
||||
/// <summary>
|
||||
/// Represents the Umbraco implementation of the PetaPoco Database object
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Currently this object exists for 'future proofing' our implementation. By having our own inheritied implementation we
|
||||
/// can then override any additional execution (such as additional loggging, functionality, etc...) that we need to without breaking compatibility since we'll always be exposing
|
||||
/// this object instead of the base PetaPoco database object.
|
||||
/// </remarks>
|
||||
public class UmbracoDatabase : Database, IDisposeOnRequestEnd
|
||||
{
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly Guid _instanceId = Guid.NewGuid();
|
||||
/// <summary>
|
||||
/// Used for testing
|
||||
/// </summary>
|
||||
internal Guid InstanceId
|
||||
{
|
||||
get { return _instanceId; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Used for testing
|
||||
/// </summary>
|
||||
internal Guid InstanceId
|
||||
{
|
||||
get { return _instanceId; }
|
||||
}
|
||||
|
||||
public UmbracoDatabase(IDbConnection connection) : base(connection)
|
||||
{
|
||||
}
|
||||
[Obsolete("Use the other constructor specifying an ILogger instead")]
|
||||
public UmbracoDatabase(IDbConnection connection)
|
||||
: this(connection, LoggerResolver.Current.Logger)
|
||||
{
|
||||
}
|
||||
|
||||
public UmbracoDatabase(string connectionString, string providerName) : base(connectionString, providerName)
|
||||
{
|
||||
}
|
||||
[Obsolete("Use the other constructor specifying an ILogger instead")]
|
||||
public UmbracoDatabase(string connectionString, string providerName)
|
||||
: this(connectionString, providerName, LoggerResolver.Current.Logger)
|
||||
{
|
||||
}
|
||||
|
||||
public UmbracoDatabase(string connectionString, DbProviderFactory provider) : base(connectionString, provider)
|
||||
{
|
||||
}
|
||||
[Obsolete("Use the other constructor specifying an ILogger instead")]
|
||||
public UmbracoDatabase(string connectionString, DbProviderFactory provider)
|
||||
: this(connectionString, provider, LoggerResolver.Current.Logger)
|
||||
{
|
||||
}
|
||||
|
||||
public UmbracoDatabase(string connectionStringName) : base(connectionStringName)
|
||||
{
|
||||
}
|
||||
[Obsolete("Use the other constructor specifying an ILogger instead")]
|
||||
public UmbracoDatabase(string connectionStringName)
|
||||
: this(connectionStringName, LoggerResolver.Current.Logger)
|
||||
{
|
||||
}
|
||||
|
||||
public UmbracoDatabase(IDbConnection connection, ILogger logger)
|
||||
: base(connection)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public UmbracoDatabase(string connectionString, string providerName, ILogger logger)
|
||||
: base(connectionString, providerName)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public UmbracoDatabase(string connectionString, DbProviderFactory provider, ILogger logger)
|
||||
: base(connectionString, provider)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public UmbracoDatabase(string connectionStringName, ILogger logger)
|
||||
: base(connectionStringName)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override IDbConnection OnConnectionOpened(IDbConnection connection)
|
||||
{
|
||||
// wrap the connection with a profiling connection that tracks timings
|
||||
return new StackExchange.Profiling.Data.ProfiledDbConnection(connection as DbConnection, MiniProfiler.Current);
|
||||
}
|
||||
|
||||
|
||||
public override void OnException(Exception x)
|
||||
{
|
||||
LogHelper.Info<UmbracoDatabase>(x.StackTrace);
|
||||
_logger.Info<UmbracoDatabase>(x.StackTrace);
|
||||
base.OnException(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user