private WebAssemblyHostEnvironment InitializeEnvironment(WebAssemblyJSRuntimeInvoker jsRuntimeInvoker)
        {
            var applicationEnvironment = jsRuntimeInvoker.InvokeUnmarshalled <object, object, object, string>(
                "Blazor._internal.getApplicationEnvironment", null, null, null);
            var hostEnvironment = new WebAssemblyHostEnvironment(applicationEnvironment, WebAssemblyNavigationManager.Instance.BaseUri);

            Services.AddSingleton <IWebAssemblyHostEnvironment>(hostEnvironment);

            var configFiles = new[]
            {
                "appsettings.json",
                $"appsettings.{applicationEnvironment}.json"
            };

            foreach (var configFile in configFiles)
            {
                var appSettingsJson = jsRuntimeInvoker.InvokeUnmarshalled <string, object, object, byte[]>(
                    "Blazor._internal.getConfig", configFile, null, null);

                if (appSettingsJson != null)
                {
                    // Perf: Using this over AddJsonStream. This allows the linker to trim out the "File"-specific APIs and assemblies
                    // for Configuration, of where there are several.
                    Configuration.Add <JsonStreamConfigurationSource>(s => s.Stream = new MemoryStream(appSettingsJson));
                }
            }

            return(hostEnvironment);
        }
        private void InitializeNavigationManager(WebAssemblyJSRuntimeInvoker jsRuntimeInvoker)
        {
            var baseUri = jsRuntimeInvoker.InvokeUnmarshalled <object, object, object, string>(BrowserNavigationManagerInterop.GetBaseUri, null, null, null);
            var uri     = jsRuntimeInvoker.InvokeUnmarshalled <object, object, object, string>(BrowserNavigationManagerInterop.GetLocationHref, null, null, null);

            WebAssemblyNavigationManager.Instance = new WebAssemblyNavigationManager(baseUri, uri);
        }
Exemplo n.º 3
0
        private void InitializeRegisteredRootComponents(WebAssemblyJSRuntimeInvoker jsRuntimeInvoker)
        {
            var componentsCount = jsRuntimeInvoker.InvokeUnmarshalled <object, object, object, int>(RegisteredComponentsInterop.GetRegisteredComponentsCount, null, null, null);

            if (componentsCount == 0)
            {
                return;
            }

            var registeredComponents = new WebAssemblyComponentMarker[componentsCount];

            for (var i = 0; i < componentsCount; i++)
            {
                var id       = jsRuntimeInvoker.InvokeUnmarshalled <int, object, object, int>(RegisteredComponentsInterop.GetId, i, null, null);
                var assembly = jsRuntimeInvoker.InvokeUnmarshalled <int, object, object, string>(RegisteredComponentsInterop.GetAssembly, id, null, null);
                var typeName = jsRuntimeInvoker.InvokeUnmarshalled <int, object, object, string>(RegisteredComponentsInterop.GetTypeName, id, null, null);
                var serializedParameterDefinitions = jsRuntimeInvoker.InvokeUnmarshalled <int, object, object, string>(RegisteredComponentsInterop.GetParameterDefinitions, id, null, null);
                var serializedParameterValues      = jsRuntimeInvoker.InvokeUnmarshalled <int, object, object, string>(RegisteredComponentsInterop.GetParameterValues, id, null, null);
                registeredComponents[i] = new WebAssemblyComponentMarker(WebAssemblyComponentMarker.ClientMarkerType, assembly, typeName, serializedParameterDefinitions, serializedParameterValues, id.ToString());
            }

            var componentDeserializer = WebAssemblyComponentParameterDeserializer.Instance;

            foreach (var registeredComponent in registeredComponents)
            {
                _rootComponentCache = new RootComponentTypeCache();
                var componentType = _rootComponentCache.GetRootComponent(registeredComponent.Assembly, registeredComponent.TypeName);
                var definitions   = componentDeserializer.GetParameterDefinitions(registeredComponent.ParameterDefinitions);
                var values        = componentDeserializer.GetParameterValues(registeredComponent.ParameterValues);
                var parameters    = componentDeserializer.DeserializeParameters(definitions, values);

                RootComponents.Add(componentType, registeredComponent.PrerenderId, parameters);
            }
        }
        /// <summary>
        /// Creates an instance of <see cref="WebAssemblyHostBuilder"/> with the minimal configuration.
        /// </summary>
        internal WebAssemblyHostBuilder(WebAssemblyJSRuntimeInvoker jsRuntimeInvoker)
        {
            // Private right now because we don't have much reason to expose it. This can be exposed
            // in the future if we want to give people a choice between CreateDefault and something
            // less opinionated.
            Configuration  = new WebAssemblyHostConfiguration();
            RootComponents = new RootComponentMappingCollection();
            Services       = new ServiceCollection();
            Logging        = new LoggingBuilder(Services);

            // Retrieve required attributes from JSRuntimeInvoker
            InitializeNavigationManager(jsRuntimeInvoker);
            InitializeDefaultServices();

            var hostEnvironment = InitializeEnvironment(jsRuntimeInvoker);

            HostEnvironment = hostEnvironment;

            _createServiceProvider = () =>
            {
                return(Services.BuildServiceProvider(validateScopes: WebAssemblyHostEnvironmentExtensions.IsDevelopment(hostEnvironment)));
            };
        }
Exemplo n.º 5
0
 // For unit testing.
 internal SatelliteResourcesLoader(WebAssemblyJSRuntimeInvoker invoker)
 {
     _invoker = invoker;
 }
Exemplo n.º 6
0
 // For unit testing.
 internal WebAssemblyCultureProvider(WebAssemblyJSRuntimeInvoker invoker, CultureInfo initialCulture, CultureInfo initialUICulture)
 {
     _invoker         = invoker;
     InitialCulture   = initialCulture;
     InitialUICulture = initialUICulture;
 }