12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
-
- using Blazorise;
- using Blazorise.Bootstrap5;
- using Blazorise.Icons.FontAwesome;
- using MudBlazor.Services;
- using MudExtensions.Services;
- using PCC2.AssemblyInject;
- using PCC2.EventBus;
- using PCC2.Init;
- using PCC2.Logging;
- namespace PCC2.AppScaffold;
- public class HostHolder
- {
- private static IHost HoldedHost;
- public static IServiceProvider ServiceProvider { get; private set; }
- public static IAsyncEventBus EventBus { get; private set; }
- public static void BuildHost()
- {
- var builder = Host.CreateApplicationBuilder();
- // 注册其他服务
- var services = builder.Services;
- services.AddAssemblyInject<HostHolder>();
- services.AddWindowsFormsBlazorWebView();
- //界面框架
- services.AddMudServices();
- services.AddMudExtensions();
- services.AddBlazorise(options => options.Immediate = true)
- .AddBootstrap5Providers()
- .AddFontAwesomeIcons();
- // 日志配置
- builder.SetLogFormatForSimpleConsole(false);
- var loggingIntoEventBus = new LoggingIntoEventBus();
- services.AddLogging(opt =>
- {
- opt.AddProvider(loggingIntoEventBus);
- opt.AddDebug();
- });
- HoldedHost = builder.Build();
- ServiceProvider = HoldedHost.Services;
- EventBus = ServiceProvider.GetRequiredService<IAsyncEventBus>();
- loggingIntoEventBus.EventBus = EventBus;
- LoggingHolder.Init(EventBus);
- }
- public static async Task StartAsync() => await HoldedHost.StartAsync();
- public static async Task StopAsync() => await HoldedHost.StopAsync();
- }
|