• DbUtils


    `

     public class DbUtils
    {
        private static object _obj = new object();
        private static IDbConnection _connection = null;
        public static IDbConnection Main
        {
            get
            {
                IDbConnection dbContext = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString);
                return dbContext;
            }
        }
        public static SQLiteConnection SqliteConnection
        {
            get
            {
                SQLiteConnectionStringBuilder sb = new SQLiteConnectionStringBuilder();
                sb.DataSource = Configs.DbPath;
                sb.Version = 3;
                sb.Password = Configs.DbPassWord;
                SQLiteConnection connection = null;
    
                if (connection == null)
                {
                    lock (_obj)
                    {
                        if (connection == null)
                        {
                            connection = new SQLiteConnection(sb.ToString());
                        }
                    }
                }
                return connection;
            }
        }
        /// <summary>
        /// using写法
        /// </summary>
        public static IDbConnection SqlServerConnection
        {
            get
            {
                IDbConnection connection = null;
                if (connection == null)
                {
                    lock (_obj)
                    {
                        if (connection == null)
                        {
                            connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString);
                        }
                    }
                }
                return connection;
            }
        }
        /// <summary>
        /// 单例
        /// </summary>
        /// <returns></returns>
        public static IDbConnection SqlServerInstance()
        {
            if (_connection == null)
            {
                lock (_obj)
                {
                    if (_connection == null) // double-check
                    {
                        _connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString);
                    }
                }
            }
            return _connection;
        }
    }
    

    `

  • 相关阅读:
    Xamarin.Forms之ToolbarItem
    Xamarin.Forms一些常见问题
    Xamarin.Forms之页面及导航
    Xamarin.Forms 自定义控件(呈现器和效果)
    Xamarin.Forms之主题
    Xamarin.Forms之样式
    Android开发
    eShopOnContainers项目
    使用Xamarin.Forms构建企业应用
    Xamarin.Forms之XAML
  • 原文地址:https://www.cnblogs.com/wangyinlon/p/13888924.html
Copyright © 2020-2023  润新知