This repository has been archived by the owner on Nov 21, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
115 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,92 @@ | ||
// 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 Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.HostFiltering; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace CreateDefaultBuilderOfTApp | ||
{ | ||
public class Program | ||
{ | ||
static void Main(string[] args) => WebHost.CreateDefaultBuilder<Startup>(new[] { "--cliKey", "cliValue" }) .Build().Run(); | ||
static void Main(string[] args) | ||
{ | ||
string responseMessage = null; | ||
|
||
WebHost.CreateDefaultBuilder(new[] { "--cliKey", "cliValue" }) | ||
.ConfigureServices((context, service) => responseMessage = responseMessage ?? GetResponseMessage(context)) | ||
.ConfigureKestrel(options => options | ||
.Configure(options.ConfigurationLoader.Configuration) | ||
.Endpoint("HTTP", endpointOptions => | ||
{ | ||
if (responseMessage == null | ||
&& !string.Equals("KestrelEndPointSettingValue", endpointOptions.ConfigSection["KestrelEndPointSettingName"])) | ||
{ | ||
responseMessage = "Default Kestrel configuration not read."; | ||
} | ||
})) | ||
.Configure(app => app.Run(context => | ||
{ | ||
// Verify allowed hosts were loaded | ||
var hostFilteringOptions = app.ApplicationServices.GetRequiredService<IOptions<HostFilteringOptions>>(); | ||
var hosts = string.Join(',', hostFilteringOptions.Value.AllowedHosts); | ||
if (responseMessage == null && !string.Equals("example.com,127.0.0.1", hosts, StringComparison.Ordinal)) | ||
{ | ||
responseMessage = "AllowedHosts not loaded into Options."; | ||
} | ||
var hostingEnvironment = app.ApplicationServices.GetRequiredService<IHostingEnvironment>(); | ||
return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName); | ||
})) | ||
.Build() | ||
.Run(); | ||
} | ||
|
||
private static string GetResponseMessage(WebHostBuilderContext context) | ||
{ | ||
// Verify ContentRootPath set | ||
var contentRoot = Environment.GetEnvironmentVariable("ASPNETCORE_CONTENTROOT"); | ||
if (!string.Equals(contentRoot, context.HostingEnvironment.ContentRootPath, StringComparison.Ordinal)) | ||
{ | ||
return $"ContentRootPath incorrect. Expected: {contentRoot} Actual: {context.HostingEnvironment.ContentRootPath}"; | ||
} | ||
|
||
// Verify appsettings.json loaded | ||
if (!string.Equals("settingsValue", context.Configuration["settingsKey"], StringComparison.Ordinal)) | ||
{ | ||
return $"appsettings.json not loaded into Configuration."; | ||
} | ||
|
||
// Verify appsettings.environment.json loaded | ||
if (!string.Equals("devSettingsValue", context.Configuration["devSettingsKey"], StringComparison.Ordinal)) | ||
{ | ||
return $"appsettings.{context.HostingEnvironment.EnvironmentName}.json not loaded into Configuration."; | ||
} | ||
|
||
// TODO: Verify UserSecrets loaded | ||
|
||
// Verify environment variables loaded | ||
if (!string.Equals("envValue", context.Configuration["envKey"], StringComparison.Ordinal)) | ||
{ | ||
return $"Environment variables not loaded into Configuration."; | ||
} | ||
|
||
// Verify command line arguments loaded | ||
if (!string.Equals("cliValue", context.Configuration["cliKey"], StringComparison.Ordinal)) | ||
{ | ||
return $"Command line arguments not loaded into Configuration."; | ||
} | ||
|
||
// TODO: Verify AddConsole called | ||
// TODO: Verify AddDebug called | ||
// TODO: Verify UseIISIntegration called | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.