TestBase.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using CZFW.Core;
  2. using CZFW.Framework;
  3. using CZFW.Framework.Logic;
  4. using CZFW.Framework.Model;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Text;
  11. namespace CZKJ.GBRS2.Test
  12. {
  13. public class TestBase
  14. {
  15. public TestBase()
  16. {
  17. ServiceProvider = TestDI.ServiceProvider;
  18. }
  19. public ServiceProvider ServiceProvider { get; set; }
  20. public TInterface GetService<TInterface>()
  21. {
  22. return ServiceProvider.GetService<TInterface>();
  23. }
  24. }
  25. public static class TestDI
  26. {
  27. private static ServiceProvider serviceProvider;
  28. public static ServiceProvider ServiceProvider
  29. {
  30. get
  31. {
  32. if (serviceProvider == null)
  33. {
  34. IServiceCollection service = new ServiceCollection();
  35. service.ConfigServies();
  36. service.AddLogging();
  37. service.ConfigureFrameworkServices();
  38. serviceProvider = service.BuildServiceProvider();
  39. CZHttpContext.ServiceProvider = serviceProvider;
  40. var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
  41. ConfigHelper.Configs = builder.Build();
  42. }
  43. return serviceProvider;
  44. }
  45. }
  46. }
  47. }