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

namespace BPA.MES.Base.Application.Services
{
    /// <summary>
    /// 名    称 ：  
    /// 创 建 人 ：yangxiao  
    /// 创建时间 ：  2023/7/17 16:13:10 
    /// 描    述 ：  
    /// </summary>
    public class BaseService: ITransient, IDynamicApiController
    {
        private readonly ISqlSugarClient _dbContext;
        public BaseService(ISqlSugarClient db)
        {
            _dbContext = db;
        }
        /// <summary>
        /// 初始化数据库
        /// </summary>
        /// <returns></returns>
        public string CreateDB()
        {
            var types = Assembly.Load("BPA.MES.Base.Application").GetTypes()
                .Where(x => x.GetCustomAttribute<SugarTable>() != null
                            && x.Namespace == "BPA.MES.Base.Application.Entitys").ToArray();
            _dbContext.CodeFirst.InitTables(types);
            return "成功";
        }
        /// <summary>
        /// 测试
        /// </summary>
        [AllowAnonymous]
        public void Test()
        {
            //Type personType = Type.GetType("BPA.MES.Base.Application, DictDataAddInput");
            //object person = Activator.CreateInstance(personType);
            Type type = Type.GetType("BPA.MES.Base.Application.Services.DictService.Dtos");
            string fullName = "BPA.MES.Base.Application.Services.DictDataAddInput";
            Type? instanceClass = Assembly.Load("BPA.MES.Base.Application").GetType(fullName);
            var myInstance = instanceClass?.Assembly.CreateInstance(fullName);
           
        }
    }
}
