OWIN 中 K Commands 与 OwinHost.exe 相等吗?

简介:
  • 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.

K Commands 是 APS.NET 5 引出的,根据说明知道它是加载与启动 OWIN 组件的一个命令,那 OwinHost.exe 是什么?它其实是之前 OWIN 的实现 Katana 项目中的一个东西,这个东西是什么?看一下源码结构:

201224518912478.png

摘自 Program.cs 中的一段源代码:

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Owin.Hosting;
using Microsoft.Owin.Hosting.Services;
using Microsoft.Owin.Hosting.Starter;
using Microsoft.Owin.Hosting.Utilities;
using OwinHost.Options;

namespace OwinHost
{
    public static class Program
    {
        public static void RunServer(StartOptions options)
        {
            if (options == null)
            {
                return;
            }

            string boot;
            if (!options.Settings.TryGetValue("boot", out boot)
                || string.IsNullOrWhiteSpace(boot))
            {
                options.Settings["boot"] = "Domain";
            }

            ResolveAssembliesFromDirectory(
                Path.Combine(Directory.GetCurrentDirectory(), "bin"));
            WriteLine("Starting with " + GetDisplayUrl(options));

            IServiceProvider services = ServicesFactory.Create();
            var starter = services.GetService<IHostingStarter>();
            IDisposable server = starter.Start(options);

            WriteLine("Started successfully");
            WriteLine("Press Enter to exit");
            Console.ReadLine();

            WriteLine("Terminating.");

            server.Dispose();
        }
    }
}

可以看到,它其实和 Microsoft.AspNet.Hosting/Program.cs 中的配置代码很相似,但不相同,Microsoft.AspNet.Hosting 是 OWIN Host 的所有概念实现,而 OwinHost 只是一个控制台启动程序,用来加载所有的 OWIN 组件,但它不包含任何的实现,比如 Host 中的 Builder、Server、Startup 等一些操作,再看下面一张图就明白了:

201323537034554.png

对,没错,OwinHost 依赖于 Microsoft.Owin.Hosting,OwinHost 中所有的 Host 操作都在 Microsoft.Owin.Hosting 中进行完成了,说白了,OwinHost 没多少东西,就是一个开启命令,和 Microsoft.AspNet.Hosting 完全不是一个概念问题,那 OwinHost 和 K Commands 相等吗?其实也不相等,只是很类似,但这个类似点只是体现在加载 OWIN 组件的时候,OwinHost 的工作就是干这个的,并且只能干这个,而 K Commands 却不仅仅如此,它还包含了其他的一些命令管理,比如“gen”、“ef”等。



本文转自田园里的蟋蟀博客园博客,原文链接:http://www.cnblogs.com/xishuai/p/OWIN-K-Commands-OwinHost.html,如需转载请自行联系原作者

相关文章
|
C++ Python
Python安装库的时候出现Error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat)
终于建了一个自己个人小站:https://huangtianyu.gitee.io,以后优先更新小站博客,欢迎进站,O(∩_∩)O~~ 折腾了很久,在StackFlow里面找到了答案。原文解决方案的地址是:点击打开链接 下面给出翻译: 打开环境变量,添加如下变量: 变量名:VS120COMNTO...
2672 0
|
C++ Python Windows
Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat)
在windows下使用python时,比如编译python的一个包,会遇到这个问题: error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat) 是说没有在电脑上找到VC9编译器。
1665 0
SharePoint自动化系列——Upload files to SharePoint library using PowerShell.
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 日常的SharePoint站点测试中,我们经常要做各种各样的数据,今天又写了几个脚本,发现自己写的脚本越来越多,所以我决定整理一下,并把一些常用的可复用的方法陆续发布上来。
1131 0
Remote Server Administration Tools windows
https://www.google.com/?gws_rd=ssl#q=rsat
613 0
powershell exploit toolkit
https://github.com/OneGet/oneget https://github.
748 0
powershell exploit post-framework
https://github.com/mattifestation/PowerSploit
600 0