public void CanGetSection() { // Arrange var initialData = new Dictionary <string, string>() { { "color", "blue" }, { "type", "car" }, { "wheels:year", "2008" }, { "wheels:count", "4" }, { "wheels:brand", "michelin" }, { "wheels:brand:type", "rally" }, }; var memoryConfig = new MemoryConfigurationSource { InitialData = initialData }; var configuration = new WebAssemblyHostConfiguration(); // Act configuration.Add(memoryConfig); var section = configuration.GetSection("wheels").AsEnumerable(makePathsRelative: true).ToDictionary(k => k.Key, v => v.Value); // Assert Assert.Equal(4, section.Count); Assert.Equal("2008", section["year"]); Assert.Equal("4", section["count"]); Assert.Equal("michelin", section["brand"]); Assert.Equal("rally", section["brand:type"]); }
/// <summary> /// Creates an instance of <see cref="WebAssemblyHostBuilder"/> with the minimal configuration. /// </summary> internal WebAssemblyHostBuilder(IJSUnmarshalledRuntime jsRuntime, JsonSerializerOptions jsonOptions) { // 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. _jsonOptions = jsonOptions; Configuration = new WebAssemblyHostConfiguration(); RootComponents = new RootComponentMappingCollection(); Services = new ServiceCollection(); Logging = new LoggingBuilder(Services); // Retrieve required attributes from JSRuntimeInvoker InitializeNavigationManager(jsRuntime); InitializeRegisteredRootComponents(jsRuntime); InitializePersistedState(jsRuntime); InitializeDefaultServices(); var hostEnvironment = InitializeEnvironment(jsRuntime); HostEnvironment = hostEnvironment; _createServiceProvider = () => { return(Services.BuildServiceProvider(validateScopes: WebAssemblyHostEnvironmentExtensions.IsDevelopment(hostEnvironment))); }; }
public void SettingValueUpdatesAllProviders() { // Arrange var initialData = new Dictionary <string, string>() { { "color", "blue" } }; var source1 = new MemoryConfigurationSource { InitialData = initialData }; var source2 = new CustomizedTestConfigurationSource(); var configuration = new WebAssemblyHostConfiguration(); // Act configuration.Add(source1); configuration.Add(source2); configuration["type"] = "car"; // Assert Assert.Equal("car", configuration["type"]); IConfigurationRoot root = configuration; Assert.All(root.Providers, provider => { provider.TryGet("type", out var value); Assert.Equal("car", value); }); }
public void CanSetAndGetConfigurationValue() { // Arrange var initialData = new Dictionary <string, string>() { { "color", "blue" }, { "type", "car" }, { "wheels:year", "2008" }, { "wheels:count", "4" }, { "wheels:brand", "michelin" }, { "wheels:brand:type", "rally" }, }; var memoryConfig = new MemoryConfigurationSource { InitialData = initialData }; var configuration = new WebAssemblyHostConfiguration(); // Act configuration.Add(memoryConfig); configuration["type"] = "car"; configuration["wheels:count"] = "6"; // Assert Assert.Equal("car", configuration["type"]); Assert.Equal("blue", configuration["color"]); Assert.Equal("6", configuration["wheels:count"]); }
public void NewConfigurationProviderOverridesOldOneWhenKeyIsDuplicated() { // Arrange var dic1 = new Dictionary <string, string>() { { "Key1:Key2", "ValueInMem1" } }; var dic2 = new Dictionary <string, string>() { { "Key1:Key2", "ValueInMem2" } }; var memConfigSrc1 = new MemoryConfigurationSource { InitialData = dic1 }; var memConfigSrc2 = new MemoryConfigurationSource { InitialData = dic2 }; var configuration = new WebAssemblyHostConfiguration(); // Act configuration.Add(memConfigSrc1); configuration.Add(memConfigSrc2); // Assert Assert.Equal("ValueInMem2", configuration["Key1:Key2"]); }
public static void ConfigureServices(IServiceCollection services, WebAssemblyHostConfiguration configuration, string baseAddress) { //Add Guid Service services.AddGuidService(); //Add DateTime Service services.AddDateTimeService(); //Add Stopwatch Service services.AddStopwatchService(); //Add Logging Service services.AddLoggingService(); //Add Redactor Service services.AddRedactorService(); services.Configure <RedactorServiceOptions>(configuration.GetSection(nameof(RedactorServiceOptions))); //Add Telemetry Service services.AddSingleton <ITelemetryService, TelemetryService>(); //Add DurableRest Service services.AddDurableRestService(); //Add Account Proxy Service services.AddAccountProxyService ( new Uri(configuration[$"{nameof(AccountProxyOptions)}:{nameof(AccountProxyOptions.BaseURL)}"]), new TimeSpan(0, 0, Convert.ToInt32(configuration[$"{nameof(AccountProxyOptions)}:{nameof(AccountProxyOptions.HttpClientTimeoutInSeconds)}"])) ); services.Configure <AccountProxyOptions>(configuration.GetSection(nameof(AccountProxyOptions))); }
private static void ConfigureServices(IServiceCollection services, WebAssemblyHostConfiguration config) { var baseApiUrl = config.GetSection("apiUrl")?.Value; services .AddBlazoredLocalStorage() .AddScoped <IAuthService, AuthService>() .AddScoped <IRecipeService, RecipeService>() .AddScoped <IToastService, ToastService>(); services.AddHttpClient(Constants.AUTH_CLIENT_NAME, client => client.BaseAddress = new Uri($"{baseApiUrl}/auth")); services.AddHttpClient(Constants.BG_PICTURE_URL_NAME, client => client.BaseAddress = new Uri($"{baseApiUrl}/api/background-picture")); services.AddHttpClient(Constants.API_CLIENT_NAME, (sp, client) => { client.BaseAddress = new Uri($"{baseApiUrl}/api"); var sfactory = sp.GetService <IServiceScopeFactory>(); using var scope = sfactory.CreateScope(); var auth = scope.ServiceProvider.GetService <IAuthService>(); var token = auth?.Token; if (token == null) { return; } client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}"); }); }
public static async Task Main(string[] args) { WebAssemblyHostBuilder builder = WebAssemblyHostBuilder.CreateDefault(args); WebAssemblyHostConfiguration configuration = builder.Configuration; IWebAssemblyHostEnvironment hostEnvironment = builder.HostEnvironment; builder.RootComponents.Add <App>("app"); AddSerilog(hostEnvironment); builder.Services.ConfigureServices(configuration, hostEnvironment) .ConfigureApplicationServices(configuration); await builder.Build().RunAsync(); }
private static void ConfigureServices(IServiceCollection services, WebAssemblyHostConfiguration configuration, IWebAssemblyHostEnvironment hostEnvironment) { services.AddHttpClient(httpClientLogicalName, client => client.BaseAddress = new Uri(hostEnvironment.BaseAddress)) .AddHttpMessageHandler <AccessTokenMessageHandler>(); //.AddHttpMessageHandler(sp => //{ // var handler = sp.GetService<AccessTokenMessageHandler>(); // configuration.Bind("IdentitySettings", handler); // return handler; //}); services.AddScoped(sp => sp.GetRequiredService <IHttpClientFactory>().CreateClient(httpClientLogicalName)); services.AddOpenidConnectPkce(settings => { configuration.Bind("IdentitySettings", settings); }); }
public void CanDisposeProviders() { // Arrange var initialData = new Dictionary <string, string>() { { "color", "blue" } }; var memoryConfig = new MemoryConfigurationSource { InitialData = initialData }; var configuration = new WebAssemblyHostConfiguration(); // Act configuration.Add(memoryConfig); Assert.Equal("blue", configuration["color"]); var exception = Record.Exception(() => configuration.Dispose()); // Assert Assert.Null(exception); }
public void CanGetChildren() { // Arrange var initialData = new Dictionary <string, string>() { { "color", "blue" } }; var memoryConfig = new MemoryConfigurationSource { InitialData = initialData }; var configuration = new WebAssemblyHostConfiguration(); // Act configuration.Add(memoryConfig); IConfiguration readableConfig = configuration; var children = readableConfig.GetChildren(); // Assert Assert.NotNull(children); Assert.NotEmpty(children); }
public void CanSupportDeeplyNestedConfigs() { // Arrange var dic1 = new Dictionary <string, string>() { { "Mem1", "Value1" }, { "Mem1:", "NoKeyValue1" }, { "Mem1:KeyInMem1", "ValueInMem1" }, { "Mem1:KeyInMem1:Deep1", "ValueDeep1" } }; var dic2 = new Dictionary <string, string>() { { "Mem2", "Value2" }, { "Mem2:", "NoKeyValue2" }, { "Mem2:KeyInMem2", "ValueInMem2" }, { "Mem2:KeyInMem2:Deep2", "ValueDeep2" } }; var dic3 = new Dictionary <string, string>() { { "Mem3", "Value3" }, { "Mem3:", "NoKeyValue3" }, { "Mem3:KeyInMem3", "ValueInMem3" }, { "Mem3:KeyInMem4", "ValueInMem4" }, { "Mem3:KeyInMem3:Deep3", "ValueDeep3" }, { "Mem3:KeyInMem3:Deep4", "ValueDeep4" } }; var memConfigSrc1 = new MemoryConfigurationSource { InitialData = dic1 }; var memConfigSrc2 = new MemoryConfigurationSource { InitialData = dic2 }; var memConfigSrc3 = new MemoryConfigurationSource { InitialData = dic3 }; var configuration = new WebAssemblyHostConfiguration(); // Act configuration.Add(memConfigSrc1); configuration.Add(memConfigSrc2); configuration.Add(memConfigSrc3); // Assert var dict = configuration.GetSection("Mem1").AsEnumerable(makePathsRelative: true).ToDictionary(k => k.Key, v => v.Value); Assert.Equal(3, dict.Count); Assert.Equal("NoKeyValue1", dict[""]); Assert.Equal("ValueInMem1", dict["KeyInMem1"]); Assert.Equal("ValueDeep1", dict["KeyInMem1:Deep1"]); var dict2 = configuration.GetSection("Mem2").AsEnumerable(makePathsRelative: true).ToDictionary(k => k.Key, v => v.Value); Assert.Equal(3, dict2.Count); Assert.Equal("NoKeyValue2", dict2[""]); Assert.Equal("ValueInMem2", dict2["KeyInMem2"]); Assert.Equal("ValueDeep2", dict2["KeyInMem2:Deep2"]); var dict3 = configuration.GetSection("Mem3").AsEnumerable(makePathsRelative: true).ToDictionary(k => k.Key, v => v.Value); Assert.Equal(5, dict3.Count); Assert.Equal("NoKeyValue3", dict3[""]); Assert.Equal("ValueInMem3", dict3["KeyInMem3"]); Assert.Equal("ValueInMem4", dict3["KeyInMem4"]); Assert.Equal("ValueDeep3", dict3["KeyInMem3:Deep3"]); Assert.Equal("ValueDeep4", dict3["KeyInMem3:Deep4"]); }
public static IServiceCollection AddInfrastructure(this IServiceCollection services, WebAssemblyHostConfiguration configuration, IWebAssemblyHostEnvironment hostEnvironment) { services.AddHttpClient(BaseService.HttpClientSecureLogicalName, client => client.BaseAddress = new Uri(hostEnvironment.BaseAddress)) .AddHttpMessageHandler <AccessTokenMessageHandler>() .AddHttpMessageHandler <CheckResponseMessageHandler>(); services.AddTransient(sp => sp.GetRequiredService <IHttpClientFactory>().CreateClient(BaseService.HttpClientSecureLogicalName)); services.AddHttpClient(BaseService.HttpClientLogicalName, client => client.BaseAddress = new Uri(hostEnvironment.BaseAddress)) .AddHttpMessageHandler <CheckResponseMessageHandler>(); services.AddTransient(sp => sp.GetRequiredService <IHttpClientFactory>().CreateClient(BaseService.HttpClientLogicalName)); var settings = new ClientSettings(); configuration.Bind("Settings", settings); services.AddSingleton(settings); services.AddTenantOpenidConnectPkce(); services.AddTransient <CheckResponseMessageHandler>(); services.AddFileReaderService(options => options.UseWasmSharedBuffer = true); return(services); }
private static void ConfigureServices(IServiceCollection services, WebAssemblyHostConfiguration configuration, IWebAssemblyHostEnvironment hostEnvironment) { services.AddInfrastructure(configuration, hostEnvironment); services.AddServices(); services.AddLogic(); }
public Startup(WebAssemblyHostConfiguration configuration, IWebAssemblyHostEnvironment hostEnvironment) { Configuration = configuration; HostEnvironment = hostEnvironment; }