zoukankan      html  css  js  c++  java
  • ASP.NET Core2,通过反射批量注入程序集

     public void ConfigureServices(IServiceCollection services)
            {
                string strValue = Configuration.GetSection("Appsetings").GetSection("key").Value;
                foreach (var item in GetClassName(strValue))
                {
                    foreach (var typeArray in item.Value)
                    {
                        services.AddScoped(typeArray, item.Key);
                    }
                }
              
                services.AddMvc();
            }
            private static Dictionary<Type, Type[]> GetClassName(string assemblyName)
            {
                if (!String.IsNullOrEmpty(assemblyName))
                {
                    Assembly assembly = Assembly.Load(assemblyName);
                    List<Type> ts = assembly.GetTypes().ToList();

                    var result = new Dictionary<Type, Type[]>();
                    foreach (var item in ts.Where(s => !s.IsInterface))
                    {
                        var interfaceType = item.GetInterfaces();
                        if (item.IsGenericType) continue;
                        result.Add(item, interfaceType);
                    }
                    return result;
                }
                return new Dictionary<Type, Type[]>();
            }

  • 相关阅读:
    SAP MM MIGO过账报错
    SAP MM MB5L事务代码'仅总计'选项初探
    SAP MM 巴西采购订单中的NCM Code
    SAP MM Storage Location Missing in MD04 Result?
    SAP MM 预留单据的历史修改记录?
    2018-8-10-上传代码-CodePlex
    2019-9-2-win10-uwp-九幽图床
    2018-2-13-win10-UWP-应用设置
    2018-2-13-win10-UWP-你写我读
    2018-2-13-win10-UWP-九幽登录
  • 原文地址:https://www.cnblogs.com/Mrkaisa/p/8431355.html
Copyright © 2011-2022 走看看