示例#1
0
        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)));
        }
    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"]);
    }
示例#3
0
        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 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"]);
    }