using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace HttpClientStudy.UnitTest { /// <summary> /// 依赖注入 框架必备设置类 /// </summary> public class Startup { /// <summary> /// 创建主机:可选,一般不用 /// </summary> /// <returns></returns> public IHostBuilder CreateHostBuilder() { return Host.CreateDefaultBuilder() ; } /// <summary> /// 配置主机:可选 /// </summary> /// <param name="hostBuilder"></param> public void ConfigureHost(IHostBuilder hostBuilder) { //hostBuilder.ConfigureWebHost(webHostBuilder => //{ // webHostBuilder // .UseTestServer() // .ConfigureTestServices(a => { }); // //webHostBuilder.UseTestServer(options => options.PreserveExecutionContext = true); // //配置默认配置项 // //webHostBuilder.ConfigureAppConfiguration((context, configBuilder) => // //{ // // configBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); // // configBuilder.AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true); // //}); // //webHostBuilder.ConfigureServices(services => // //{ // // services.AddHealthChecks(); // //}); //}); } /// <summary> /// 注册服务:必须 /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { //services.AddTransient<IDependency, DependencyClass>(); } } }