Files
T-DAS/Epost.DAL/DB_DLL.cs
2023-01-13 15:30:20 +08:00

80 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Epost.DAL
{
public class DB_DLL
{
private static DataBaseOpration.OprationSqlDAL db;
/// <summary>
/// 程序运行时,创建一个静态只读的进程辅助对象
/// </summary>
private static readonly object _object = new object();
// //SqlLocDPSConnection
public static string _conn = ConfigurationManager.ConnectionStrings["SqlLocDPSConnection"].ConnectionString;
/// <summary>
/// 构造方法私有外键不能通过New类实例化此类
/// </summary>
private DB_DLL()
{
}
/// <summary>
/// 此方法是本类实例的唯一全局访问点
/// (双重加锁 Double-Check Locking
/// </summary>
/// <returns></returns>
public static DataBaseOpration.OprationSqlDAL GetInstance()
{
//先判断实例是否存在,不存在再加锁处理
if (db == null)
{
//在同一时刻加了锁的那部分程序只有一个线程可以进入,
lock (_object)
{
//如实例不存在则New一个新实例否则返回已有实例
if (db == null)
{
db = new DataBaseOpration.OprationSqlDAL(_conn);
}
}
}
return db;
}
}
}