最近.net core 1.1也发布了,蹒跚学步的小孩又长高了一些,园子里大家也都非常积极的在学习,闲来无事,扒拔源码,涨涨见识。
先来见识一下web站点是如何启动的,如何接受请求,.net core web app最简单的例子,大约长这样
public static void Main(string[] args) { //dotnet NetCoreWebApp.dll --server.urls="http://localhost:5000/;http://localhost:5001/" var config = new ConfigurationBuilder().AddCommandLine(args).Build(); new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory()) //.UseIISIntegration() .UseStartup<Startup>() //.Configure(confApp => //{ // confApp.Run(context => // { // return context.Response.WriteAsync("hello"); // }); //}) .Build()
.Run();
}
WebHostBuilder看名字也知道是为了构建WebHost而存在的。在构建WebHost的路上他都做了这些:如加载配置,注册服务,配置功能等。
