国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

OWIN 中 K Commands(OwinHost.exe)與 Microsoft.AspNet.Hosting 的角色問題

2019-11-17 01:58:38
字體:
來源:轉載
供稿:網友

OWIN 中 K Commands(OwinHost.exe)與 Microsoft.aspNet.Hosting 的角色問題

問題詳情:K Commands(OwinHost.exe)是不是 OWIN 中的 Host 角色?如果是,那 Microsoft.AspNet.Hosting 對應的是 OWIN 中的哪個角色?

OWIN 中,除了 Host 和 Server 的概念容易混淆,K Commands(OwinHost.exe)與 Microsoft.AspNet.Hosting 也是很容易混淆的一點,先看一下它們的概念:

  • OwinHost.exe: While some will want to write a custom PRocess to run Katana Web applications, many would prefer to simply launch a pre-built executable that can start a server and run their application. For this scenario, the Katana component suite includes OwinHost.exe. When run from within a project’s root directory, this executable will start a server (it uses the HttpListener server by default) and use conventions to find and run the user’s startup class. For more granular control, the executable provides a number of additional command line parameters.
  • K Commands: Whenever you want to run your app in command line using K* commands, you will use k run. The K command is your entry point to the runtime. To run an application you can use K run to build you can use K build, and all other commands that are about taking your application and running it.
  • Microsoft.AspNet.Hosting: The Hosting repo contains code required to host an asp.net vNext application, it is the entry point used when self-hosting an application.

上面是從網上各個地方搜刮的概念,再來結合 Microsoft.AspNet.Hosting/Program.cs 的源碼

using System;using System.IO;using System.Threading;using System.Threading.Tasks;using Microsoft.Framework.ConfigurationModel;using Microsoft.Framework.DependencyInjection;using Microsoft.Framework.DependencyInjection.Fallback;using Microsoft.Framework.Logging;using Microsoft.Framework.Runtime;namespace Microsoft.AspNet.Hosting{    public class Program    {        private const string HostingIniFile = "Microsoft.AspNet.Hosting.ini";        private readonly IServiceProvider _serviceProvider;        public Program(IServiceProvider serviceProvider)        {            _serviceProvider = serviceProvider;        }        public void Main(string[] args)        {            var config = new Configuration();            if (File.Exists(HostingIniFile))            {                config.AddIniFile(HostingIniFile);            }            config.AddEnvironmentVariables();            config.AddCommandLine(args);            var services = HostingServices.Create(_serviceProvider, config)                .BuildServiceProvider();            var appEnv = services.GetRequiredService<IApplicationEnvironment>();            var hostingEnv = services.GetRequiredService<IHostingEnvironment>();            var context = new HostingContext()            {                Services = services,                Configuration = config,                ServerName = config.Get("server"), // TODO: Key names                ApplicationName = config.Get("app")  // TODO: Key names                    ?? appEnv.ApplicationName,                EnvironmentName = hostingEnv.EnvironmentName,            };            var engine = services.GetRequiredService<IHostingEngine>();            var loggerFactory = services.GetRequiredService<ILoggerFactory>();            var appShutdownService = _serviceProvider.GetRequiredService<IApplicationShutdown>();            var shutdownHandle = new ManualResetEvent(false);            var serverShutdown = engine.Start(context);            appShutdownService.ShutdownRequested.Register(() =>            {                try                {                    serverShutdown.Dispose();                }                catch (Exception ex)                {                    var logger = loggerFactory.Create<Program>();                    logger.WriteError("TODO: Dispose threw an exception", ex);                }                shutdownHandle.Set();            });            var ignored = Task.Run(() =>            {                Console.WriteLine("Started");                Console.ReadLine();                appShutdownService.RequestShutdown();            });            shutdownHandle.WaitOne();        }    }}

K Commands(OwinHost.exe)的作用就是啟動并加載 OWIN 組件,使你的應用程序處于運行狀態,看上面 Program.cs 代碼,就會發現 Microsoft.AspNet.Hosting 其實就是一個控制臺項目,當然除此之外還會包含 Builder、Server、Startup 等一些操作,這些構成了基本的 OWIN Host,它是一個進程,負責啟動并加載 OWIN 組件(在之前的博文中有說明),而 K Commands(OwinHost.exe)只不過是一個命令,用來去開啟它,就像一個車鑰匙,用來發動汽車一樣。結合 IIS 的一些東西,K Commands(OwinHost.exe)就像我們點擊“啟動”、“停止” 的后臺處理命令,當然還有一些 URL 綁定等,這些都通過命令去加載,過程大概是這樣:K Commands -> project.json -> Microsoft.AspNet.Hosting -> Started。

在之前曾說過,如果采用 IIS 的部署,那 ASP.NET 5 的 project.json 配置,就是下面這么簡單:

{    "webroot": "wwwroot",    "dependencies": {        "Microsoft.AspNet.Server.IIS": "1.0.0-beta1"    }}

你會發現,沒有了 Microsoft.AspNet.Hosting、Microsoft.AspNet.Server.WebListener,也沒有了 Commands,為什么呢?因為 IIS 既是 Host,又是 Server,IIS 與 ASP.NET 5 的 OWIN 管道處理,是通過 Microsoft.AspNet.Server.IIS(AspNet.Loader.dll)打通的,所以 OWIN 的處理組件都是通過 IIS,這時候的 ASP.NET 5 其實就不是純粹的 OWIN。

回答上面的問題,K Commands(OwinHost.exe)不是 OWIN 中的 Host 角色,Microsoft.AspNet.Hosting 才是,應該準確的說,K Commands(OwinHost.exe)和 OWIN 中的 Host 不存在概念問題,它只是一個命令,用來開啟 Microsoft.AspNet.Hosting,Microsoft.AspNet.Hosting 是 OWIN 中 Host 概念的具體體現。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 山阴县| 阳高县| 西乌珠穆沁旗| 兴隆县| 上林县| 隆林| 梅州市| 沁源县| 克什克腾旗| 独山县| 汽车| 当阳市| 金昌市| 黔东| 颍上县| 偃师市| 明溪县| 绿春县| 江川县| 津南区| 商南县| 鄱阳县| 游戏| 舞钢市| 长顺县| 唐山市| 沾化县| 华坪县| 格尔木市| 防城港市| 崇明县| 马山县| 沈丘县| 甘肃省| 沅陵县| 溧阳市| 碌曲县| 新密市| 凤冈县| 璧山县| 威信县|