using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HighWayIot.Repository
{
    public class Repository<T> : SimpleClient<T> where T : class, new()

    {
        public Repository(dynamic configId)
        {
            /**
             * 根据configId动态获取数据源
             */
            base.Context = SqlSugarHelper.Db.GetConnectionScope(configId);

            //.NET自带IOC:  base.Context = 你存储的Services.GetService<ISqlSugarClient>(); 
            //Furion:       base.Context=App.GetService<ISqlSugarClient>();
            //Furion脚手架:    base.Context=DbContext.Instance
            //SqlSugar.Ioc:    base.Context=DbScoped.SugarScope; 
            //手动去赋值:     base.Context=DbHelper.GetDbInstance()     

            //动态添加
            //if (!SqlSugarHelper.Db.IsAnyConnection("用户读出来的数据库ConfigId")) 
            //{
            //    SqlSugarHelper.Db.AddConnection(new ConnectionConfig() { 数据库读出来信息 });
            //}
            //base.Context = SqlSugarHelper.Db.GetConnectionScope("用户读出来的数据库ConfigId");
        }

        public SqlSugarScope _db()
        {
            return base.Context as SqlSugarScope;
        }
    }
}

