DbCtxt.ConnStr = Configuration.GetSection("ConnectionString").Value;

            // 根据类是否添加注解[IsService]来自动注入
            var assm = new[] { typeof(Program).Assembly, typeof(DbCtxt).Assembly };
            foreach (var ass in assm)
            {
                var types = ass.GetTypes();
                foreach (var typ in types)
                {
                    var typeInfo = typ.GetTypeInfo();
                    if (typeInfo.IsDefined(typeof(IsService)))
                    {
                        services.AddScoped(typ);
                        var interfaces = typeInfo.ImplementedInterfaces;
                        foreach (var item in interfaces)
                        {
                            services.AddScoped(item, typ);
                        }
                    }
                }
            }

 

相关文章:

  • 2022-02-07
  • 2021-11-26
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2021-09-28
  • 2021-06-06
  • 2022-02-12
猜你喜欢
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2021-09-10
  • 2022-12-23
  • 2021-11-14
  • 2021-11-09
相关资源
相似解决方案