首页 新闻 会员 周边

asp.net5

0
悬赏园豆:5 [已解决问题] 解决于 2018-04-13 11:43

今天学习asp.net5  用vs2017创建了一个MVC项目,进入入口文件,发现里面的一段代码看不懂,代码如下:

  public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();

求大神帮忙解释一下。谢谢了。

彭满意的主页 彭满意 | 初学一级 | 园豆:103
提问于:2017-10-19 16:11
< >
分享
最佳答案
1

新写法?

百度了一下

public static IWebHostBuilder CreateDefaultBuilder(string[] args)
{
    var builder = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            var env = hostingContext.HostingEnvironment;
 
            config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                  .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
 
            if (env.IsDevelopment())
            {
                var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
                if (appAssembly != null)
                {
                    config.AddUserSecrets(appAssembly, optional: true);
                }
            }
 
            config.AddEnvironmentVariables();
 
            if (args != null)
            {
                config.AddCommandLine(args);
            }
        })
        .ConfigureLogging((hostingContext, logging) =>
        {
            logging.UseConfiguration(hostingContext.Configuration.GetSection("Logging"));
            logging.AddConsole();
            logging.AddDebug();
        })
        .UseIISIntegration()
        .UseDefaultServiceProvider((context, options) =>
        {
            options.ValidateScopes = context.HostingEnvironment.IsDevelopment();
        })
        .ConfigureServices(services =>
        {
            services.AddTransient<IConfigureOptions<KestrelServerOptions>, KestrelServerOptionsSetup>();
        });
 
    return builder;
}
收获园豆:5
猝不及防 | 老鸟四级 |园豆:2781 | 2017-10-19 17:22
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册