Skip to content
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

TodosApi updates #1836

Merged
merged 18 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scenarios/goldilocks.benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ scenarios:
- "/p:PublishAot=true"
- "/p:StripSymbols=true"
environmentVariables:
CONNECTIONSTRINGS__TODODB: Server={{databaseServer}};Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4
APPSETTINGS__CONNECTIONSTRING: Server={{databaseServer}};Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4
load:
job: wrk
variables:
Expand All @@ -131,7 +131,7 @@ scenarios:
- "/p:TrimMode=full"
- "/p:EnableRequestDelegateGenerator=true"
environmentVariables:
CONNECTIONSTRINGS__TODODB: Server={{databaseServer}};Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4
APPSETTINGS__CONNECTIONSTRING: Server={{databaseServer}};Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4
load:
job: wrk
variables:
Expand All @@ -147,7 +147,7 @@ scenarios:
- "/p:PublishAot=false"
- "/p:EnableRequestDelegateGenerator=false"
environmentVariables:
CONNECTIONSTRINGS__TODODB: Server={{databaseServer}};Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4
APPSETTINGS__CONNECTIONSTRING: Server={{databaseServer}};Database=hello_world;User Id=benchmarkdbuser;Password=benchmarkdbpass;Maximum Pool Size=256;NoResetOnClose=true;Enlist=false;Max Auto Prepare=4
load:
job: wrk
variables:
Expand Down
10 changes: 10 additions & 0 deletions src/BenchmarksApps.sln
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorUnited", "BenchmarksA
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TodosApi", "BenchmarksApps\TodosApi\TodosApi.csproj", "{8E1A1F61-43E4-4629-A25B-7E5FA82697D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore.OpenApi", "BenchmarksApps\AspNetCore.OpenApi\AspNetCore.OpenApi.csproj", "{28F432A6-1328-4996-91DD-BB1C87F45BF2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_Database|Any CPU = Debug_Database|Any CPU
Expand Down Expand Up @@ -207,6 +209,14 @@ Global
{8E1A1F61-43E4-4629-A25B-7E5FA82697D0}.Release_Database|Any CPU.Build.0 = Release_Database|Any CPU
{8E1A1F61-43E4-4629-A25B-7E5FA82697D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E1A1F61-43E4-4629-A25B-7E5FA82697D0}.Release|Any CPU.Build.0 = Release|Any CPU
{28F432A6-1328-4996-91DD-BB1C87F45BF2}.Debug_Database|Any CPU.ActiveCfg = Debug_Database|Any CPU
{28F432A6-1328-4996-91DD-BB1C87F45BF2}.Debug_Database|Any CPU.Build.0 = Debug_Database|Any CPU
{28F432A6-1328-4996-91DD-BB1C87F45BF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28F432A6-1328-4996-91DD-BB1C87F45BF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28F432A6-1328-4996-91DD-BB1C87F45BF2}.Release_Database|Any CPU.ActiveCfg = Release_Database|Any CPU
{28F432A6-1328-4996-91DD-BB1C87F45BF2}.Release_Database|Any CPU.Build.0 = Release_Database|Any CPU
{28F432A6-1328-4996-91DD-BB1C87F45BF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28F432A6-1328-4996-91DD-BB1C87F45BF2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
17 changes: 17 additions & 0 deletions src/BenchmarksApps/AspNetCore.OpenApi/AspNetCore.OpenApi.csproj
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>
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>
17 changes: 17 additions & 0 deletions src/BenchmarksApps/AspNetCore.OpenApi/OpenApiFeature.cs
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;
}
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>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
DamianEdwards marked this conversation as resolved.
Show resolved Hide resolved
"BasicMinimalApi": {
"commandName": "Project",
Expand Down
13 changes: 13 additions & 0 deletions src/BenchmarksApps/DistributedCache/Properties/launchSettings.json
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"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"BasicGrpc": {
"commandName": "Project",
Expand Down
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"
}
}
}
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 src/BenchmarksApps/HelloWorldMvc/Properties/launchSettings.json
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 src/BenchmarksApps/MapAction/Properties/launchSettings.json
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"
}
}
}
13 changes: 13 additions & 0 deletions src/BenchmarksApps/Mvc/Properties/launchSettings.json
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"
}
}
}
13 changes: 13 additions & 0 deletions src/BenchmarksApps/SignalR/Properties/launchSettings.json
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 src/BenchmarksApps/StaticFiles/Properties/launchSettings.json
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"
}
}
}
13 changes: 13 additions & 0 deletions src/BenchmarksApps/TcpEcho/Properties/launchSettings.json
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"
}
}
}
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"
}
}
}
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 src/BenchmarksApps/TechEmpower/Mvc/Properties/launchSettings.json
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"
}
}
}
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"
}
}
}
61 changes: 61 additions & 0 deletions src/BenchmarksApps/TodosApi/AppSettings.cs
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;
}
}
4 changes: 4 additions & 0 deletions src/BenchmarksApps/TodosApi/DataExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System.Data;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Options;
using TodosApi;

namespace Npgsql;

// Replace this with https://www.nuget.org/packages/Nanorm once it's ready

internal static class DataExtensions
{
public static async Task<int> ExecuteAsync(this NpgsqlDataSource dataSource, string commandText, CancellationToken cancellationToken = default)
Expand Down
Loading