Reacting to new Hosting API

This commit is contained in:
John Luo 2015-12-16 12:34:36 -08:00
parent 717b355bfd
commit bd10d507f8
15 changed files with 133 additions and 117 deletions

View File

@ -1,3 +0,0 @@

Server = Microsoft.AspNet.Server.Kestrel
Server.Urls = http://localhost:5001/

View File

@ -1,9 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
namespace LargeResponseApp namespace LargeResponseApp
{ {
@ -34,5 +35,15 @@ namespace LargeResponseApp
} }
}); });
} }
public static void Main(string[] args)
{
var application = new WebApplicationBuilder()
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
.UseStartup<Startup>()
.Build();
application.Run();
}
} }
} }

View File

@ -0,0 +1,4 @@
{
"server": "Microsoft.AspNet.Server.Kestrel",
"server.urls": "http://localhost:5001/"
}

View File

@ -3,14 +3,14 @@
"dependencies": { "dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*" "Microsoft.AspNet.Server.Kestrel": "1.0.0-*"
}, },
"compilationOptions": {
"emitEntryPoint": true
},
"frameworks": { "frameworks": {
"dnx451": { }, "dnx451": { },
"dnxcore50": { } "dnxcore50": { }
}, },
"commands": { "commands": {
"run": "Microsoft.AspNet.Server.Kestrel", "web": "LargeResponseApp"
"web": "Microsoft.AspNet.Hosting"
} }
} }

View File

@ -1,17 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
namespace SampleApp
{
public class Program
{
public static void Main(string[] args)
{
var mergedArgs = new[] { "--server", "Microsoft.AspNet.Server.Kestrel" }.Concat(args).ToArray();
Microsoft.AspNet.Hosting.Program.Main(mergedArgs);
}
}
}

View File

@ -5,6 +5,7 @@ using System;
using System.IO; using System.IO;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel;
@ -61,5 +62,20 @@ namespace SampleApp
await context.Response.WriteAsync("Hello world"); await context.Response.WriteAsync("Hello world");
}); });
} }
public static void Main(string[] args)
{
var application = new WebApplicationBuilder()
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
.UseStartup<Startup>()
.Build();
// The following section should be used to demo sockets
//var addresses = application.GetAddresses();
//addresses.Clear();
//addresses.Add("http://unix:/tmp/kestrel-test.sock");
application.Run();
}
} }
} }

View File

@ -0,0 +1,4 @@
{
"server": "Microsoft.AspNet.Server.Kestrel",
"server.urls": "http://localhost:5000;https://localhost:5001"
}

View File

@ -5,6 +5,9 @@
"Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*",
"Microsoft.Extensions.Logging.Console": "1.0.0-*" "Microsoft.Extensions.Logging.Console": "1.0.0-*"
}, },
"compilationOptions": {
"emitEntryPoint": true
},
"frameworks": { "frameworks": {
"dnx451": { "dnx451": {
}, },
@ -15,8 +18,6 @@
} }
}, },
"commands": { "commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000;https://localhost:5001", "web": "SampleApp"
"kestrel": "Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000;https://localhost:5001",
"run-socket": "Microsoft.AspNet.Server.Kestrel --server.urls http://unix:/tmp/kestrel-test.sock"
} }
} }

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" forwardWindowsAuthToken="false" startupTimeLimit="3600" />
</system.webServer>
</configuration>

View File

@ -1,17 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
namespace Microsoft.AspNet.Server.Kestrel
{
public class Program
{
public static void Main(string[] args)
{
var mergedArgs = new[] { "--server", "Microsoft.AspNet.Server.Kestrel" }.Concat(args).ToArray();
Microsoft.AspNet.Hosting.Program.Main(mergedArgs);
}
}
}

View File

@ -40,11 +40,12 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}) })
.Build(); .Build();
var hostBuilder = new WebHostBuilder(config); var applicationBuilder = new WebApplicationBuilder()
hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); .UseConfiguration(config)
hostBuilder.UseStartup(ConfigureEchoAddress); .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.Configure(ConfigureEchoAddress);
using (var app = hostBuilder.Build().Start()) using (var app = applicationBuilder.Build().Start())
{ {
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {

View File

@ -79,9 +79,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
{ "server.urls", registerAddress } { "server.urls", registerAddress }
}).Build(); }).Build();
var builder = new WebHostBuilder(config) var builder = new WebApplicationBuilder()
.UseConfiguration(config)
.UseServerFactory("Microsoft.AspNet.Server.Kestrel") .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.UseStartup(app => .Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
{ {

View File

@ -29,9 +29,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}) })
.Build(); .Build();
var hostBuilder = new WebHostBuilder(config); var applicationBuilder = new WebApplicationBuilder()
hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); .UseConfiguration(config)
hostBuilder.UseStartup(app => .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
{ {
@ -53,7 +54,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}); });
}); });
using (var app = hostBuilder.Build().Start()) using (var app = applicationBuilder.Build().Start())
{ {
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {
@ -97,9 +98,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
{ "server.urls", "http://localhost:8791" } { "server.urls", "http://localhost:8791" }
}).Build(); }).Build();
var builder = new WebHostBuilder(config) var builder = new WebApplicationBuilder()
.UseConfiguration(config)
.UseServerFactory("Microsoft.AspNet.Server.Kestrel") .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.UseStartup(app => .Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
{ {
@ -126,9 +128,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
{ "server.urls", $"http://{registerAddress}:{port}" } { "server.urls", $"http://{registerAddress}:{port}" }
}).Build(); }).Build();
var builder = new WebHostBuilder(config) var builder = new WebApplicationBuilder()
.UseConfiguration(config)
.UseServerFactory("Microsoft.AspNet.Server.Kestrel") .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.UseStartup(app => .Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
{ {

View File

@ -28,9 +28,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}) })
.Build(); .Build();
var hostBuilder = new WebHostBuilder(config); var applicationBuilder = new WebApplicationBuilder()
hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); .UseConfiguration(config)
hostBuilder.UseStartup(app => .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
{ {
@ -49,7 +50,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}); });
}); });
using (var app = hostBuilder.Build().Start()) using (var app = applicationBuilder.Build().Start())
{ {
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {
@ -85,9 +86,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}) })
.Build(); .Build();
var hostBuilder = new WebHostBuilder(config) var hostBuilder = new WebApplicationBuilder()
.UseConfiguration(config)
.UseServerFactory("Microsoft.AspNet.Server.Kestrel") .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.UseStartup(app => .Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
{ {

View File

@ -24,9 +24,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}) })
.Build(); .Build();
var hostBuilder = new WebHostBuilder(config); var applicationBuilder = new WebApplicationBuilder()
hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); .UseConfiguration(config)
hostBuilder.UseStartup(app => .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.Configure(app =>
{ {
var serverInfo = app.ServerFeatures.Get<IKestrelServerInformation>(); var serverInfo = app.ServerFeatures.Get<IKestrelServerInformation>();
serverInfo.ThreadCount = threadCount; serverInfo.ThreadCount = threadCount;
@ -36,7 +37,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}); });
}); });
using (var app = hostBuilder.Build().Start()) using (var app = applicationBuilder.Build().Start())
{ {
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {