HostHolder.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using PCC.Common.AssemblyInject;
  2. using PCC.Common.EventBus;
  3. using PCC.Common.Init;
  4. using PCC.Common.Logging;
  5. using PCC.Gui.MudIse;
  6. using PCC.Logging;
  7. namespace PCC.AppScaffold;
  8. public static class HostHolder
  9. {
  10. private static IHost HoldedHost;
  11. public static IServiceProvider ServiceProvider { get; private set; }
  12. public static IEventBus EventBus { get; private set; }
  13. public static void BuildHost()
  14. {
  15. var builder = Host.CreateApplicationBuilder();
  16. // 注册其他服务
  17. var services = builder.Services;
  18. services.AddAssemblyInject<PccGuiProgram>();
  19. services.AddWindowsFormsBlazorWebView();
  20. //界面框架
  21. services.AddMudIseOnPcc();
  22. // 日志配置
  23. builder.SetLogFormatForSimpleConsole(false);
  24. var loggingIntoEventBus = new LoggingIntoEventBus();
  25. services.AddLogging(opt => opt.AddProvider(loggingIntoEventBus));
  26. HoldedHost = builder.Build();
  27. ServiceProvider = HoldedHost.Services;
  28. EventBus = ServiceProvider.GetRequiredService<IEventBus>();
  29. loggingIntoEventBus.EventBus = EventBus;
  30. LoggingHolder.Init(EventBus);
  31. }
  32. public static async Task StartAsync() => await HoldedHost.StartAsync();
  33. public static async Task StopAsync() => await HoldedHost.StopAsync();
  34. }