public void Configure(DesktopApplicationBuilder app, IServiceProvider services) { try { var method = GetConfigureMethod(); Debug.Assert(method != null); var parameters = method.GetParameters(); var arguments = new object[parameters.Length]; for (var i = 0; i < parameters.Length; i++) { var parameter = parameters[i]; arguments[i] = parameter.ParameterType == typeof(DesktopApplicationBuilder) ? app : services.GetRequiredService(parameter.ParameterType); } method.Invoke(Instance, arguments); } catch (Exception ex) { if (ex is TargetInvocationException) { ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); } throw; } }
private static async Task RunAsync <TStartup>(IPC ipc, CancellationToken appLifetime, ManualResetEventSlim completed) { var configurationBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true); Dispatcher = new PlatformDispatcher(appLifetime); Dispatcher.Context.UnhandledException += (sender, exception) => { UnhandledException(exception); }; DesktopJSRuntime = new DesktopJSRuntime(ipc); completed.Set(); // await PerformHandshakeAsync(ipc); AttachJsInterop(ipc, Dispatcher.Context, appLifetime); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <IConfiguration>(configurationBuilder.Build()); serviceCollection.AddLogging(configure => configure.AddConsole()); serviceCollection.AddSingleton <NavigationManager>(DesktopNavigationManager.Instance); serviceCollection.AddSingleton <IJSRuntime>(DesktopJSRuntime); serviceCollection.AddSingleton <INavigationInterception, DesktopNavigationInterception>(); serviceCollection.AddSingleton(photinoWindow); var startup = new ConventionBasedStartup(Activator.CreateInstance(typeof(TStartup))); startup.ConfigureServices(serviceCollection); var services = serviceCollection.BuildServiceProvider(); var builder = new DesktopApplicationBuilder(services); startup.Configure(builder, services); var loggerFactory = services.GetRequiredService <ILoggerFactory>(); DesktopRenderer = new DesktopRenderer(services, ipc, loggerFactory, DesktopJSRuntime, Dispatcher); DesktopRenderer.UnhandledException += (sender, exception) => { Console.Error.WriteLine(exception); }; await PerformHandshakeAsync(ipc); foreach (var rootComponent in builder.Entries) { await Dispatcher.InvokeAsync(async() => await DesktopRenderer.AddComponentAsync(rootComponent.componentType, rootComponent.domElementSelector)); } // TODO this was in BlazorDesktopToBrowser //DesktopNavigationManager.Instance.NavigateTo("/"); }