自己ホスト型アプリ (提供する Web サービスの URL を起動して表示するコンソール アプリ) をリファクタリングして、owin ではなく純粋な vnext で動作するようにできるかどうか疑問に思っていました。
オーウィンコードは次のとおりです
namespace Selfhostingtest
{
class Program
{
static void Main(string[] args)
{
String strHostName = string.Empty;
strHostName = Dns.GetHostName();
Console.WriteLine("Local Machine's Host Name: " + strHostName);
var options = new StartOptions();
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
if (!addr[i].IsIPv6LinkLocal && addr[i].AddressFamily == AddressFamily.InterNetwork)
{
Console.WriteLine("IPv4 Address {0}: {1} ", i, addr[i].ToString());
options.Urls.Add(String.Format("http://{0}:5000/", addr[i].ToString()));
}
}
using (WebApp.Start<Startup>(options))
{
Console.WriteLine("Razor server is running. Press enter to shut down...");
Console.ReadLine();
}
}
}
}
記録として、「k web」コマンド ライン スタートを使用したくありません。vnext アプリを実行可能ファイルとして完全にパッケージ化したい。
Microsoft.Owin.Hosting の代わりに、Microsoft.AspNet.Hosting を使用する必要があります (「k web」コマンド定義と同じクラスです。Owin スタートアップは IAppBuilder を想定し、vnext は IBuilder を想定していることに注意してください。