Skip to content

Commit

Permalink
.NET Core 3 Upgrade (#112)
Browse files Browse the repository at this point in the history
# Boxed.AspNetCore

- Upgrade to .NET Core 3 SDK and target `netcoreapp3.0`.
- Switch from NuGet `PackageIconUrl` to `PackageIcon`, so the icon is now embedded in the package.
- Upgrade `Micorosoft.Extensions.*` NuGet packages to `3.0.0`.
- Switch from `Newtonsoft.Json` to `System.Text.Json`.
- `DistributedCacheExtensions` now uses `System.Text.Json` and serializes directly to UTF8 for performance reasons.
- Use Ordinal string comparisons.
- Switch from `IHostingEnvironment` to `IWebHostEnvironment`.
- `RedirectToCanonicalUrlRule` implements `Microsoft.AspNetCore.Rewrite.IRule` and can be used to redirect to a single canonical URL. This used to be an MVC filter.
- `HttpExceptionMiddleware` now implements `IMiddleware`.
- Remove site map code. Look at the source code for the The ASP.NET Core standup site for how to do this in a better way.
- Remove `UrlHelperExtensions`. Use `LinkGenerator` instead.
- Remove `ConfigurationExtensions.GetSection<T>`. Use `IConfiguration.Get` instead.
- Remove `InternalServerErrorOnExceptionMiddleware` since it was unused.
- Remove `NoCacheAttribute`.

# Boxed.AspNetCore.Swagger

- Upgrade to .NET Core 3 SDK and target `netcoreapp3.0`.
- Upgrade to `Swashbuckle.AspNetCore` version `5.0.0-rc4` for Open API 3 support.
- Switch from NuGet `PackageIconUrl` to `PackageIcon`, so the icon is now embedded in the package.
- Added `CorrelationIdOperationFilter` operation filter.
- Added `ProblemDetails` schema filter but this is not yet working so it's internal for now. See domaindrivendev/Swashbuckle.AspNetCore#985.
- Removed `ModelStateDictionary`'s schema filter.

# Boxed.AspNetCore.TagHelpers

- Upgrade to .NET Core 3 SDK and target `netcoreapp3.0`.
- Switch from NuGet `PackageIconUrl` to `PackageIcon`, so the icon is now embedded in the package.

# Boxed.DotnetNewTest

- Upgrade to .NET Core 3 SDK and target `netstandard2.1` and `netcoreapp3.0`.
- Switch from NuGet `PackageIconUrl` to `PackageIcon`, so the icon is now embedded in the package.
- Use Ordinal file path string comparisons.
- Move experimental `DotnetRunInMemoryAsync` to be `netcoreapp3.0` only due to API limitations.

# Boxed.Mapping

- Upgrade to .NET Core 3 SDK and target `netstandard1.3`, `netstandard2.0` and `netstandard2.1`.
- Switch from NuGet `PackageIconUrl` to `PackageIcon`, so the icon is now embedded in the package.
- Add extension methods adding support for `IAsyncEnumerable<T>`.
  • Loading branch information
RehanSaeed committed Nov 11, 2019
1 parent 9673cb9 commit d4c3f9e
Show file tree
Hide file tree
Showing 114 changed files with 2,005 additions and 2,940 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

<ItemGroup Label="Package References">
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
<!-- See https://github.com/Microsoft/dotnet/tree/master/releases/reference-assemblies -->
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" Version="1.0.0-preview.2" />
</ItemGroup>

<ItemGroup Label="Analyzer Package References">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="All" Version="16.3.52" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="All" Version="16.4.16" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.118" />
</ItemGroup>

Expand Down
7 changes: 4 additions & 3 deletions Benchmarks/Boxed.Mapping.Benchmark/MapArrayBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ namespace Boxed.Mapping.Benchmark
using System.Globalization;
using AutoMapper;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Boxed.Mapping.Benchmark.Mapping;
using Boxed.Mapping.Benchmark.Models;

[KeepBenchmarkFiles]
[ClrJob]
[CoreJob]
[MemoryDiagnoser]
[MinColumn]
[MaxColumn]
[HtmlExporter]
[CsvMeasurementsExporter]
[RPlotExporter]
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net472)]
[SimpleJob(RuntimeMoniker.NetCoreApp30)]
public class MapArrayBenchmark
{
private readonly IMapper automapper;
Expand Down
7 changes: 4 additions & 3 deletions Benchmarks/Boxed.Mapping.Benchmark/MapListBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ namespace Boxed.Mapping.Benchmark
using System.Globalization;
using AutoMapper;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Boxed.Mapping.Benchmark.Mapping;
using Boxed.Mapping.Benchmark.Models;

[KeepBenchmarkFiles]
[ClrJob]
[CoreJob]
[MemoryDiagnoser]
[MinColumn]
[MaxColumn]
[HtmlExporter]
[CsvMeasurementsExporter]
[RPlotExporter]
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net472)]
[SimpleJob(RuntimeMoniker.NetCoreApp30)]
public class MapListBenchmark
{
private readonly IMapper automapper;
Expand Down
7 changes: 4 additions & 3 deletions Benchmarks/Boxed.Mapping.Benchmark/MapObjectBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ namespace Boxed.Mapping.Benchmark
using System.Globalization;
using AutoMapper;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Boxed.Mapping.Benchmark.Mapping;
using Boxed.Mapping.Benchmark.Models;

[KeepBenchmarkFiles]
[ClrJob]
[CoreJob]
[MemoryDiagnoser]
[MinColumn]
[MaxColumn]
[HtmlExporter]
[CsvMeasurementsExporter]
[RPlotExporter]
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net472)]
[SimpleJob(RuntimeMoniker.NetCoreApp30)]
public class MapObjectBenchmark
{
private readonly IMapper automapper;
Expand Down
4 changes: 2 additions & 2 deletions Benchmarks/Boxed.Mapping.Benchmark/Mapping/BoxedMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class BoxedMapper : IMapper<MapFrom, MapTo>
{
public void Map(MapFrom source, MapTo destination)
{
if (source == null)
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}

if (destination == null)
if (destination is null)
{
throw new ArgumentNullException(nameof(destination));
}
Expand Down
120 changes: 60 additions & 60 deletions Source/Boxed.AspNetCore.Swagger/Boxed.AspNetCore.Swagger.csproj
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Build">
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CodeAnalysisRuleSet>../../MinimumRecommendedRulesWithStyleCop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<PropertyGroup Label="Package">
<VersionPrefix>5.1.0</VersionPrefix>
<Authors>Muhammad Rehan Saeed (RehanSaeed.com)</Authors>
<Product>ASP.NET Core Swagger Framework Boxed</Product>
<Description>Provides ASP.NET Core middleware, MVC filters, extension methods and helper code for an ASP.NET Core project implementing Swagger (OpenAPI).</Description>
<Copyright>Copyright © Muhammad Rehan Saeed. All rights Reserved</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Dotnet-Boxed/Framework</PackageProjectUrl>
<PackageIcon>Icon-256x256.png</PackageIcon>
<RepositoryUrl>https://github.com/Dotnet-Boxed/Framework.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>ASP.NET;ASP.NET Core;MVC;Boxed;Muhammad Rehan Saeed;Framework;Swagger;OpenAPI;Swashbuckle</PackageTags>
<PackageReleaseNotes>https://github.com/Dotnet-Boxed/Framework/releases</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup Label="Signing">
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../Key.snk</AssemblyOriginatorKeyFile>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
</PropertyGroup>

<PropertyGroup Label="Source Link">
<!-- Optional: Declare that the Repository URL can be published to NuSpec -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<!-- Optional: Embed source files that are not tracked by the source control manager to the PDB -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<!-- Optional: Include PDB in the built .nupkg -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<ItemGroup Label="Project References">
<ProjectReference Include="..\Boxed.AspNetCore\Boxed.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" Version="1.0.0-beta2-19367-01" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
</ItemGroup>

<ItemGroup Label="Analyzer Package References">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="all" Version="2.9.4" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="All" Version="16.3.52" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.118" />
</ItemGroup>

<ItemGroup Label="Files">
<None Include="..\..\Images\Icon-256x256.png" Pack="true" PackagePath="\"/>
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Build">
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CodeAnalysisRuleSet>../../MinimumRecommendedRulesWithStyleCop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<PropertyGroup Label="Package">
<VersionPrefix>6.0.0</VersionPrefix>
<Authors>Muhammad Rehan Saeed (RehanSaeed.com)</Authors>
<Product>ASP.NET Core Swagger Framework Boxed</Product>
<Description>Provides ASP.NET Core middleware, MVC filters, extension methods and helper code for an ASP.NET Core project implementing Swagger (OpenAPI).</Description>
<Copyright>Copyright © Muhammad Rehan Saeed. All rights Reserved</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Dotnet-Boxed/Framework</PackageProjectUrl>
<PackageIcon>Icon-256x256.png</PackageIcon>
<RepositoryUrl>https://github.com/Dotnet-Boxed/Framework.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>ASP.NET;ASP.NET Core;MVC;Boxed;Muhammad Rehan Saeed;Framework;Swagger;OpenAPI;Swashbuckle</PackageTags>
<PackageReleaseNotes>https://github.com/Dotnet-Boxed/Framework/releases</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup Label="Signing">
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../../Key.snk</AssemblyOriginatorKeyFile>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
</PropertyGroup>

<PropertyGroup Label="Source Link">
<!-- Optional: Declare that the Repository URL can be published to NuSpec -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<!-- Optional: Embed source files that are not tracked by the source control manager to the PDB -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<!-- Optional: Include PDB in the built .nupkg -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<ItemGroup Label="Project References">
<ProjectReference Include="..\Boxed.AspNetCore\Boxed.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" Version="1.0.0-beta2-19554-01" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
</ItemGroup>

<ItemGroup Label="Analyzer Package References">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="all" Version="2.9.7" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="all" Version="16.4.16" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="all" Version="1.1.118" />
</ItemGroup>

<ItemGroup Label="Files">
<None Include="..\..\Images\Icon-256x256.png" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Boxed.AspNetCore.Swagger.OperationFilters
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Authorization.Infrastructure;
using Swashbuckle.AspNetCore.Swagger;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

/// <summary>
Expand All @@ -13,19 +13,25 @@ namespace Boxed.AspNetCore.Swagger.OperationFilters
/// <seealso cref="IOperationFilter" />
public class ClaimsOperationFilter : IOperationFilter
{
/// <summary>
/// Applies the specified operation.
/// </summary>
/// <param name="operation">The operation.</param>
/// <param name="context">The context.</param>
public void Apply(Operation operation, OperationFilterContext context)
private const string OAuth2OpenApiReferenceId = "oauth2";
private static readonly OpenApiSecurityScheme OAuth2OpenApiSecurityScheme = new OpenApiSecurityScheme()
{
if (operation == null)
Reference = new OpenApiReference()
{
Id = OAuth2OpenApiReferenceId,
Type = ReferenceType.SecurityScheme,
},
};

/// <inheritdoc/>
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (operation is null)
{
throw new ArgumentNullException(nameof(operation));
}

if (context == null)
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
Expand All @@ -34,15 +40,16 @@ public void Apply(Operation operation, OperationFilterContext context)
var authorizationRequirements = filterDescriptors.GetPolicyRequirements();
var claimTypes = authorizationRequirements
.OfType<ClaimsAuthorizationRequirement>()
.Select(x => x.ClaimType);
.Select(x => x.ClaimType)
.ToList();
if (claimTypes.Any())
{
operation.Security = new List<IDictionary<string, IEnumerable<string>>>()
operation.Security = new List<OpenApiSecurityRequirement>()
{
new Dictionary<string, IEnumerable<string>>()
new OpenApiSecurityRequirement()
{
{ "oauth2", claimTypes }
}
{ OAuth2OpenApiSecurityScheme, claimTypes },
},
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace Boxed.AspNetCore.Swagger.OperationFilters
{
using System;
using System.Collections.Generic;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

/// <summary>
/// Adds an Open API <see cref="OpenApiParameter"/> to all operations with a description of the X-Correlation-ID
/// HTTP header and a default GUID value.
/// </summary>
/// <seealso cref="IOperationFilter" />
public class CorrelationIdOperationFilter : IOperationFilter
{
/// <inheritdoc/>
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (operation is null)
{
throw new ArgumentNullException(nameof(operation));
}

if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (operation.Parameters is null)
{
operation.Parameters = new List<OpenApiParameter>();
}

operation.Parameters.Add(this.GetCorrelationIdParameter());
}

/// <summary>
/// Gets the Open API parameter for the X-Correlation-ID HTTP header.
/// </summary>
/// <returns>The Open API parameter for the X-Correlation-ID HTTP header.</returns>
protected virtual OpenApiParameter GetCorrelationIdParameter() =>
new OpenApiParameter()
{
Description = "Used to uniquely identify the HTTP request. This ID is used to correlate the HTTP request between a client and server.",
In = ParameterLocation.Header,
Name = "X-Correlation-ID",
Required = false,
Schema = new OpenApiSchema()
{
Default = new OpenApiString(Guid.NewGuid().ToString()),
Type = "string",
},
};
}
}
Loading

0 comments on commit d4c3f9e

Please sign in to comment.