using CrazyStudio.Core.Common.Tools.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CrazyStudio.Core.Common.Tools.Extensions
{
    public static class ApiExtension
    {
        /// <summary>
        /// 业务逻辑API配置
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        public static void AddLogicApis(this IServiceCollection services, Type businessType)
        {
            //注入Api相关类
            Assembly? businessAssembly = Assembly.GetAssembly(businessType);
            if (businessAssembly != null)
            {
                var types = businessAssembly.GetTypes();
                foreach (var t in types)
                {
                    if (!t.IsInterface && t.GetInterface(businessType.Name) != null)
                    {
                        services.AddSingleton(t);
                    }
                }
            }
        }
    }
}
