using PCC.Common.AssemblyInject; using PCC.Common.EventBus; using PCC.Common.Init; using PCC.Common.Logging; using PCC.Gui.MudIse; using PCC.Logging; namespace PCC.AppScaffold; public static class HostHolder { private static IHost HoldedHost; public static IServiceProvider ServiceProvider { get; private set; } public static IEventBus EventBus { get; private set; } public static void BuildHost() { var builder = Host.CreateApplicationBuilder(); // 注册其他服务 var services = builder.Services; services.AddAssemblyInject(); services.AddWindowsFormsBlazorWebView(); //界面框架 services.AddMudIseOnPcc(); // 日志配置 builder.SetLogFormatForSimpleConsole(false); var loggingIntoEventBus = new LoggingIntoEventBus(); services.AddLogging(opt => opt.AddProvider(loggingIntoEventBus)); HoldedHost = builder.Build(); ServiceProvider = HoldedHost.Services; EventBus = ServiceProvider.GetRequiredService(); loggingIntoEventBus.EventBus = EventBus; LoggingHolder.Init(EventBus); } public static async Task StartAsync() => await HoldedHost.StartAsync(); public static async Task StopAsync() => await HoldedHost.StopAsync(); }