using OrderSystem.Entity; using OrderSystem.Services.SystemSetting; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.Loader; using System.Threading.Tasks; namespace OrderSystem.Web { public static class ServiceConfiguration { public static void RegistLocalServices(IServiceCollection services) { List types = typeof(UserService).Assembly .GetTypes() .Where(x => !x.IsInterface && !x.IsAbstract && x.Name.Contains("Service")) .ToList(); var extInterfaces = new List(); foreach (var item in types) { var interfaceTypes = item.GetInterfaces(); foreach (var interfaceType in interfaceTypes) { //跳过个性化配置涉及的类 if (!extInterfaces.Any(x => x.FullName == interfaceType.FullName)) { services.AddScoped(interfaceType, item); } } } //services.BuildServiceProvider(); } } }