ServiceConfiguration.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using OrderSystem.Entity;
  2. using OrderSystem.Services.SystemSetting;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Runtime.Loader;
  10. using System.Threading.Tasks;
  11. namespace OrderSystem.Web
  12. {
  13. public static class ServiceConfiguration
  14. {
  15. public static void RegistLocalServices(IServiceCollection services)
  16. {
  17. List<Type> types = typeof(UserService).Assembly
  18. .GetTypes()
  19. .Where(x => !x.IsInterface && !x.IsAbstract && x.Name.Contains("Service"))
  20. .ToList();
  21. var extInterfaces = new List<Type>();
  22. foreach (var item in types)
  23. {
  24. var interfaceTypes = item.GetInterfaces();
  25. foreach (var interfaceType in interfaceTypes)
  26. {
  27. //跳过个性化配置涉及的类
  28. if (!extInterfaces.Any(x => x.FullName == interfaceType.FullName))
  29. {
  30. services.AddScoped(interfaceType, item);
  31. }
  32. }
  33. }
  34. //services.BuildServiceProvider();
  35. }
  36. }
  37. }