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.Name == "IApplicationBuilder"
                        ? app
                        : services.GetRequiredService(parameter.ParameterType);
                }

                method.Invoke(Instance, arguments);
            }
            catch (Exception ex)
            {
                if (ex is TargetInvocationException)
                {
                    ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
                }

                throw;
            }
        }
Esempio n. 2
0
        private static async Task RunAsync <TStartup>(IPC ipc, CancellationToken appLifetime)
        {
            DesktopJSRuntime = new DesktopJSRuntime(ipc);
            await PerformHandshakeAsync(ipc);

            AttachJsInterop(ipc, appLifetime);

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging(configure => configure.AddConsole());
            serviceCollection.AddSingleton <NavigationManager>(DesktopNavigationManager.Instance);
            serviceCollection.AddSingleton <IJSRuntime>(DesktopJSRuntime);
            serviceCollection.AddSingleton <INavigationInterception, DesktopNavigationInterception>();

            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);
            DesktopRenderer.UnhandledException += (sender, exception) =>
            {
                Console.Error.WriteLine(exception);
            };

            foreach (var rootComponent in builder.Entries)
            {
                _ = DesktopRenderer.AddComponentAsync(rootComponent.componentType, rootComponent.domElementSelector);
            }
        }