-
Notifications
You must be signed in to change notification settings - Fork 243
TodosApi updates #1836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
TodosApi updates #1836
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9b12562
Add launchSettings.json for all BenchmarksApps projects
DamianEdwards 1a5dbdb
WIP: TodosApi: Bind AppSettings from configuration
DamianEdwards 2b125e6
TodosApi: Update yml scenarios for AppSettings
DamianEdwards f217076
Update TodosApi.http
DamianEdwards 594f15b
Generate OpenAPI doc on build
DamianEdwards b7ccd33
Update TodosApi.csproj
DamianEdwards 825ca9c
More changes to enable OpenAPI doc generation
DamianEdwards 35de349
Disable MapShortCircuit due to issue
DamianEdwards 91a056b
Updates
DamianEdwards 2f85f8b
Add OpenAPI runtime feature to trim related code in Release builds
DamianEdwards 08daa96
Don't require database config/init if run as part of the build
DamianEdwards e3d54ad
Add schema to launchSettings.json files
DamianEdwards 3429565
Delete dotnet-tools.json
DamianEdwards 7af808e
Refactor environment check
DamianEdwards 5f42e33
Update src/BenchmarksApps/TodosApi/DatabaseConfiguration.cs
DamianEdwards 991b98e
Update appsettings.json
DamianEdwards 60ffb53
Merge branch 'damianedwards/stage2-configbinding' of https://github.c…
DamianEdwards 51ee72e
Update TodosApi.http
DamianEdwards File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
17 changes: 17 additions & 0 deletions
17
src/BenchmarksApps/AspNetCore.OpenApi/AspNetCore.OpenApi.csproj
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0-preview.4.*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="ILLink.Substitutions.xml" LogicalName="ILLink.Substitutions.xml" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
src/BenchmarksApps/AspNetCore.OpenApi/ILLink.Substitutions.xml
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<linker> | ||
<assembly fullname="AspNetCore.OpenApi"> | ||
<type fullname="Microsoft.AspNetCore.OpenApi.OpenApiFeature"> | ||
<method signature="System.Boolean get_IsEnabled()" body="stub" value="false" | ||
feature="Microsoft.AspNetCore.OpenApi.OpenApiFeature.IsEnabled" featurevalue="false"/> | ||
</type> | ||
</assembly> | ||
</linker> |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Microsoft.AspNetCore.OpenApi; | ||
|
||
public static class OpenApiFeature | ||
{ | ||
/// <summary> | ||
/// Indicates whether APIs related to OpenAPI/Swagger functionality are enabled. | ||
/// </summary> | ||
/// <remarks> | ||
/// The value of the property is backed by the "Microsoft.AspNetCore.OpenApi.OpenApiFeature.IsEnabled" | ||
/// <see cref="AppContext"/> setting and defaults to <see langword="true"/> if unset. | ||
/// </remarks> | ||
public static bool IsEnabled { get; } = | ||
AppContext.TryGetSwitch( | ||
switchName: "Microsoft.AspNetCore.OpenApi.OpenApiFeature.IsEnabled", | ||
isEnabled: out var value) | ||
? value : true; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/BenchmarksApps/AspNetCore.OpenApi/build/AspNetCore.OpenApi.targets
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<OpenApiEnabled Condition=" '$(OpenApiEnabled)' == '' and $(Configuration.StartsWith('Release')) and ('$(OpenApiGenerateDocuments)' != 'true') ">false</OpenApiEnabled> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<RuntimeHostConfigurationOption Include="Microsoft.AspNetCore.OpenApi.OpenApiFeature.IsEnabled" | ||
Condition=" '$(OpenApiEnabled)' != '' " | ||
Value="$(OpenApiEnabled)" | ||
Trim="true" /> | ||
</ItemGroup> | ||
|
||
</Project> |
1 change: 1 addition & 0 deletions
1
src/BenchmarksApps/BasicMinimalApi/Properties/launchSettings.json
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
src/BenchmarksApps/DistributedCache/Properties/launchSettings.json
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"DistributedCache": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53684;http://localhost:53687" | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/BenchmarksApps/Grpc/BasicGrpc/Properties/launchSettings.json
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
src/BenchmarksApps/Grpc/GrpcHttpApiServer/Server/Properties/launchSettings.json
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"Server": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53695;http://localhost:53696" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/BenchmarksApps/HelloWorldMiddleware/Properties/launchSettings.json
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"HelloWorldMiddleware": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53681;http://localhost:53682" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/BenchmarksApps/HelloWorldMvc/Properties/launchSettings.json
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"HelloWorldMvc": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53675;http://localhost:53678" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/BenchmarksApps/MapAction/Properties/launchSettings.json
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"MapAction": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53676;http://localhost:53679" | ||
} | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"Mvc": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53683;http://localhost:53685" | ||
} | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"BenchmarkServer": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53697;http://localhost:53698" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/BenchmarksApps/StaticFiles/Properties/launchSettings.json
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"StaticFiles": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53686;http://localhost:53688" | ||
} | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"TcpEcho": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53701;http://localhost:53702" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/BenchmarksApps/TechEmpower/BlazorUnited/Properties/launchSettings.json
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"BlazorUnited": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53703;http://localhost:53704" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/BenchmarksApps/TechEmpower/Minimal/Properties/launchSettings.json
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"Minimal": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53691;http://localhost:53692" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/BenchmarksApps/TechEmpower/Mvc/Properties/launchSettings.json
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"Mvc": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53693;http://localhost:53694" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Properties/launchSettings.json
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"PlatformBenchmarks": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:53705;http://localhost:53706" | ||
} | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace TodosApi; | ||
|
||
internal class AppSettings | ||
{ | ||
public required string ConnectionString { get; set; } | ||
|
||
public string? JwtSigningKey { get; set; } | ||
|
||
public bool SuppressDbInitialization { get; set; } | ||
} | ||
|
||
// Change to using ValidateDataAnnotations once https://github.com/dotnet/runtime/issues/77412 is complete | ||
internal class AppSettingsValidator : IValidateOptions<AppSettings> | ||
{ | ||
public ValidateOptionsResult Validate(string? name, AppSettings options) | ||
{ | ||
if (string.IsNullOrEmpty(options.ConnectionString)) | ||
{ | ||
return ValidateOptionsResult.Fail(""" | ||
Connection string not found. | ||
If running locally, set the connection string in user secrets for key 'AppSettings:ConnectionString'. | ||
If running after deployment, set the connection string via the environment variable 'APPSETTINGS__CONNECTIONSTRING'. | ||
"""); | ||
} | ||
|
||
return ValidateOptionsResult.Success; | ||
} | ||
} | ||
|
||
internal static class AppSettingsExtensions | ||
{ | ||
public static IServiceCollection ConfigureAppSettings(this IServiceCollection services, IConfigurationRoot configurationRoot, IHostEnvironment hostEnvironment) | ||
{ | ||
// Can't use the configuration binding source generator due to bug where it emits non-compiling code right now | ||
// https://github.com/dotnet/runtime/issues/83600 | ||
var optionsBuilder = services.Configure<AppSettings>(configurationRoot.GetSection(nameof(AppSettings))) | ||
.AddOptions<AppSettings>(); | ||
|
||
if (!hostEnvironment.IsBuild()) | ||
{ | ||
services.AddSingleton<IValidateOptions<AppSettings>, AppSettingsValidator>(); | ||
optionsBuilder.ValidateOnStart(); | ||
} | ||
|
||
// Change to using BindConfiguration once https://github.com/dotnet/runtime/issues/83600 is complete | ||
//services.AddSingleton<IValidateOptions<AppSettings>, AppSettingsValidator>() | ||
// .AddOptions<AppSettings>() | ||
// .BindConfiguration(nameof(AppSettings)) | ||
// .ValidateOnStart(); | ||
|
||
// Change to using ValidateDataAnnotations once https://github.com/dotnet/runtime/issues/77412 is complete | ||
//services.AddOptions<AppSettings>() | ||
// .BindConfiguration(nameof(AppSettings)) | ||
// .ValidateDataAnnotations() | ||
// .ValidateOnStart(); | ||
|
||
return services; | ||
} | ||
} |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.