public async Task RunAsync_CallingTwiceCausesException() { // Arrange var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime()); var host = builder.Build(); host.CultureProvider = new TestSatelliteResourcesLoader(); var cts = new CancellationTokenSource(); var task = host.RunAsyncCore(cts.Token); // Act var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => host.RunAsyncCore(cts.Token)); cts.Cancel(); await task.TimeoutAfter(TimeSpan.FromSeconds(3)); // Assert Assert.Equal("The host has already started.", ex.Message); }
public void Build_AllowsConfiguringContainer_WithDelegate() { // Arrange var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime()); builder.Services.AddScoped <StringBuilder>(); var factory = new MyFakeServiceProviderFactory(); builder.ConfigureContainer(factory, builder => { builder.ServiceCollection.AddScoped <List <string> >(); }); // Act var host = builder.Build(); // Assert Assert.True(factory.CreateServiceProviderCalled); Assert.NotNull(host.Services.GetRequiredService <StringBuilder>()); Assert.NotNull(host.Services.GetRequiredService <List <string> >()); }
public static IAbpApplicationWithExternalServiceProvider AddApplication <TStartupModule>( [NotNull] this WebAssemblyHostBuilder builder, Action <AbpWebAssemblyApplicationCreationOptions> options) where TStartupModule : IAbpModule { Check.NotNull(builder, nameof(builder)); // Related this commit(https://github.com/dotnet/aspnetcore/commit/b99d805bc037fcac56afb79abeb7d5a43141c85e) // Microsoft.AspNetCore.Blazor.BuildTools has been removed in net 5.0. // This call may be removed when we find a suitable solution. // System.Runtime.CompilerServices.AsyncStateMachineAttribute Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add <AsyncStateMachineAttribute>(); builder.Services.AddSingleton <IConfiguration>(builder.Configuration); builder.Services.AddSingleton(builder); var application = builder.Services.AddApplication <TStartupModule>(opts => { options?.Invoke(new AbpWebAssemblyApplicationCreationOptions(builder, opts)); }); return(application); }
/// <summary> /// Configure builder for Blazor UI. /// </summary> /// <param name="builder"></param> public static void ConfigureBlazorUI(this WebAssemblyHostBuilder builder) { builder.RootComponents.Add <HeadOutlet>("head::after"); }
/// <summary> /// /// </summary> /// <typeparam name="TConfiguration"></typeparam> /// <typeparam name="TAppState"></typeparam> /// <typeparam name="TMessageHandler"></typeparam> /// <param name="builder"></param> /// <param name="configSectionName"></param> /// <returns></returns> /// <remarks>If your <typeparamref name="TMessageHandler"/> needs a constructor, register it before making this call.</remarks> public static WebAssemblyHostBuilder AddBlazorEssentials <TConfiguration, TAppState, TMessageHandler>(this WebAssemblyHostBuilder builder, string configSectionName) where TConfiguration : ConfigurationBase where TAppState : AppStateBase where TMessageHandler : DelegatingHandler { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (string.IsNullOrWhiteSpace(configSectionName)) { throw new ArgumentNullException(nameof(configSectionName)); } var config = builder.Services.AddConfigurationBase <TConfiguration>(builder.Configuration, configSectionName); builder.Services.AddAppStateBase <TAppState>(); builder.Services.AddHttpClients <TConfiguration, TMessageHandler>(config); return(builder); }
/// <summary> /// Registers the necessary services to bootstrap BlazorEssentials, including a <see cref="ConfigurationBase"/>, <see cref="AppStateBase"/>, and /// <see cref="HttpClient">HttpClients</see> for interacting with both the /// </summary> /// <typeparam name="TConfiguration"></typeparam> /// <typeparam name="TAppState"></typeparam> /// <param name="builder"></param> /// <param name="configSectionName"></param> /// <returns></returns> public static WebAssemblyHostBuilder AddBlazorEssentials <TConfiguration, TAppState>(this WebAssemblyHostBuilder builder, string configSectionName) where TConfiguration : ConfigurationBase where TAppState : AppStateBase { return(AddBlazorEssentials <TConfiguration, TAppState, BlazorEssentialsAuthorizationMessageHandler <TConfiguration> >(builder, configSectionName)); }