Пример #1
0
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder
            .UseEnvironment("BuildTest")
            .UseDefaultServiceProvider(p => p.ValidateScopes = true)
            .ConfigureServices((context, services) =>
            {
                // configure our petstore with a unique host so that we can mock it using different urls than other services we might want to mock
                services.PostConfigure <PetStoreOptions>(o =>
                {
                    o.Url = "http://petstore";
                });

                // since we registered with a named client, we can configure it so that we can mock all the requests and responses
                services.AddHttpClient(PetStoreOptions.HttpClientName).ConfigurePrimaryHttpMessageHandler(() => PetStoreMockHandler);

                AdditionalServices?.Invoke(context, services);
            })
            .ConfigureAppConfiguration((context, configurationBuilder) =>
            {
                AdditionalConfiguration?.Invoke(context, configurationBuilder);
            })
            .ConfigureLogging((context, builder) =>
            {
                builder.ClearProviders();
                // values are picked up from appsetting.json
                builder.AddProvider(_loggerProvider);

                // log level cannot be modified here since this is triggered after the configuration settings have been established
                // need to make changes in the AdditionalConfiguration since that happens earlier in the lifecycle
                AdditionalLogging?.Invoke(context, builder);
            });
        }