using PushInfo.Act.IDAL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace PushInfo.Act
{
    internal class DALFactory
    {
        /// <summary>
        /// 使用的数据库，配置名称必须和DAL文件夹下的对应数据库文件夹名称相同
        /// </summary>
        private static readonly string _DB = ConfigurationManager.AppSettings["DB"];

        /// <summary>
        /// DAL 程序集名称
        /// </summary>
        private static readonly string _AssemblyName = "PushInfo.Act";

        public static ISysPushDAL CreateSysPushDAL()
        {
            return CreateDAL<ISysPushDAL>("SysPushDAL");
        }

        public static IMapProjectPushDAL CreateMapProjectPushDAL()
        {
            return CreateDAL<IMapProjectPushDAL>("MapProjectPushDAL");
        }

        public static ISelectItemDAL CreateSelectItemDAL()
        {
            return CreateDAL<ISelectItemDAL>("SelectItemDAL");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T">IDAL接口</typeparam>
        /// <param name="dalName"></param>
        /// <returns></returns>
        private static T CreateDAL<T>(string dalName)
        {
            string classFullName = string.Concat(_AssemblyName, ".DAL.", _DB, ".", dalName);
            return (T)Assembly.Load(_AssemblyName).CreateInstance(classFullName);
        }
    }
}
