1234567891011121314151617181920212223242526272829303132333435363738394041 |
- 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<Type> types = typeof(UserService).Assembly
- .GetTypes()
- .Where(x => !x.IsInterface && !x.IsAbstract && x.Name.Contains("Service"))
- .ToList();
- var extInterfaces = new List<Type>();
-
- 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();
- }
- }
- }
|