Skip to content

Updated dependencies to .NET 5 with EF Core 5 #1022

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 6 commits into from
Jul 23, 2021
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
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"jetbrains.resharper.globaltools": {
"version": "2021.1.3",
"version": "2021.1.4",
"commands": [
"jb"
]
Expand All @@ -21,7 +21,7 @@
]
},
"dotnet-reportgenerator-globaltool": {
"version": "4.8.9",
"version": "4.8.12",
"commands": [
"reportgenerator"
]
Expand Down
10 changes: 5 additions & 5 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project>
<PropertyGroup>
<NetCoreAppVersion>netcoreapp3.1</NetCoreAppVersion>
<AspNetCoreVersion>3.1.*</AspNetCoreVersion>
<EFCoreVersion>3.1.*</EFCoreVersion>
<NpgsqlPostgreSQLVersion>3.1.*</NpgsqlPostgreSQLVersion>
<NetCoreAppVersion>net5.0</NetCoreAppVersion>
<AspNetCoreVersion>5.0.*</AspNetCoreVersion>
<EFCoreVersion>5.0.*</EFCoreVersion>
<NpgsqlPostgreSQLVersion>5.0.*</NpgsqlPostgreSQLVersion>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

Expand All @@ -22,7 +22,7 @@
<!-- Test Project Dependencies -->
<PropertyGroup>
<BogusVersion>33.0.2</BogusVersion>
<CoverletVersion>3.0.3</CoverletVersion>
<CoverletVersion>3.1.0</CoverletVersion>
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
<MoqVersion>4.16.1</MoqVersion>
<XUnitVersion>2.4.*</XUnitVersion>
Expand Down
2 changes: 2 additions & 0 deletions JsonApiDotNetCore.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$, $NAME$);</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LocalizableElement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LoopCanBePartlyConvertedToQuery/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MemberCanBeInternal/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MethodHasAsyncOverload/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MethodHasAsyncOverloadWithCancellation/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PatternAlwaysMatches/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PublicConstructorInAbstractClass/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantArrayCreationExpression/@EntryIndexedValue">SUGGESTION</s:String>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ See also our [versioning policy](./VERSIONING_POLICY.md).
| .NET Version | EF Core Version | JsonApiDotNetCore Version |
| ----------------- | --------------- | ------------------------- |
| .NET Core 2.x | 2.x | v3.x |
| .NET Core 3.1 | 3.1, 5 | v4 |
| .NET 5 | 5 | v4 |
| .NET Core 3.1 | 3.1, 5 | v4.x |
| .NET 5 | 5 | v4.x, v5.x |


## Contributing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static void GetNamespaceFromPathUsingReadOnlySpan(string path, string re

if (isAtEnd || hasDelimiterAfterSegment)
{
_ = pathSpan.Slice(0, index).ToString();
_ = pathSpan[..index].ToString();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/Query/QueryParserBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ namespace Benchmarks.Query
[MemoryDiagnoser]
public class QueryParserBenchmarks
{
private readonly DependencyFactory _dependencyFactory = new DependencyFactory();
private readonly FakeRequestQueryStringAccessor _queryStringAccessor = new FakeRequestQueryStringAccessor();
private readonly DependencyFactory _dependencyFactory = new();
private readonly FakeRequestQueryStringAccessor _queryStringAccessor = new();
private readonly QueryStringReader _queryStringReaderForSort;
private readonly QueryStringReader _queryStringReaderForAll;

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Serialization/JsonApiDeserializerBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class JsonApiDeserializerBenchmarks
}
});

private readonly DependencyFactory _dependencyFactory = new DependencyFactory();
private readonly DependencyFactory _dependencyFactory = new();
private readonly IJsonApiDeserializer _jsonApiDeserializer;

public JsonApiDeserializerBenchmarks()
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/Serialization/JsonApiSerializerBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ namespace Benchmarks.Serialization
[MarkdownExporter]
public class JsonApiSerializerBenchmarks
{
private static readonly BenchmarkResource Content = new BenchmarkResource
private static readonly BenchmarkResource Content = new()
{
Id = 123,
Name = Guid.NewGuid().ToString()
};

private readonly DependencyFactory _dependencyFactory = new DependencyFactory();
private readonly DependencyFactory _dependencyFactory = new();
private readonly IJsonApiSerializer _jsonApiSerializer;

public JsonApiSerializerBenchmarks()
Expand Down
2 changes: 1 addition & 1 deletion src/Examples/ReportsExample/Services/ReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private IReadOnlyCollection<Report> GetReports()
{
return new List<Report>
{
new Report
new()
{
Title = "Status Report",
Statistics = new ReportStatistics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace JsonApiDotNetCore.AtomicOperations.Processors
public class SetRelationshipProcessor<TResource, TId> : ISetRelationshipProcessor<TResource, TId>
where TResource : class, IIdentifiable<TId>
{
private readonly CollectionConverter _collectionConverter = new CollectionConverter();
private readonly CollectionConverter _collectionConverter = new();
private readonly ISetRelationshipService<TResource, TId> _service;

public SetRelationshipProcessor(ISetRelationshipService<TResource, TId> service)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void ResolveRelationships(IReadOnlyCollection<RelationshipAttribute> rel
{
if (!(relationship is HasManyThroughAttribute))
{
INavigation inverseNavigation = entityType.FindNavigation(relationship.Property.Name)?.FindInverse();
INavigation inverseNavigation = entityType.FindNavigation(relationship.Property.Name)?.Inverse;
relationship.InverseNavigationProperty = inverseNavigation?.PropertyInfo;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace JsonApiDotNetCore.Configuration
/// </summary>
internal sealed class JsonApiApplicationBuilder : IJsonApiApplicationBuilder, IDisposable
{
private readonly JsonApiOptions _options = new JsonApiOptions();
private readonly JsonApiOptions _options = new();
private readonly IServiceCollection _services;
private readonly IMvcCoreBuilder _mvcBuilder;
private readonly ResourceGraphBuilder _resourceGraphBuilder;
Expand Down
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public sealed class JsonApiOptions : IJsonApiOptions
public bool IncludeTotalResourceCount { get; set; }

/// <inheritdoc />
public PageSize DefaultPageSize { get; set; } = new PageSize(10);
public PageSize DefaultPageSize { get; set; } = new(10);

/// <inheritdoc />
public PageSize MaximumPageSize { get; set; }
Expand Down Expand Up @@ -80,7 +80,7 @@ public sealed class JsonApiOptions : IJsonApiOptions
public IsolationLevel? TransactionIsolationLevel { get; set; }

/// <inheritdoc />
public JsonSerializerSettings SerializerSettings { get; } = new JsonSerializerSettings
public JsonSerializerSettings SerializerSettings { get; } = new()
{
ContractResolver = new DefaultContractResolver
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public bool ShouldValidateEntry(ValidationEntry entry, ValidationEntry parentEnt

var httpContextAccessor = _serviceProvider.GetRequiredService<IHttpContextAccessor>();

if (httpContextAccessor.HttpContext.Request.Method == HttpMethods.Patch || request.OperationKind == OperationKind.UpdateResource)
if (httpContextAccessor.HttpContext!.Request.Method == HttpMethods.Patch || request.OperationKind == OperationKind.UpdateResource)
{
var targetedFields = _serviceProvider.GetRequiredService<ITargetedFields>();
return IsFieldTargeted(entry, targetedFields);
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/Configuration/PageNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace JsonApiDotNetCore.Configuration
[PublicAPI]
public sealed class PageNumber : IEquatable<PageNumber>
{
public static readonly PageNumber ValueOne = new PageNumber(1);
public static readonly PageNumber ValueOne = new(1);

public int OneBasedValue { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ namespace JsonApiDotNetCore.Configuration
/// </summary>
internal sealed class ResourceDescriptorAssemblyCache
{
private readonly TypeLocator _typeLocator = new TypeLocator();

private readonly Dictionary<Assembly, IReadOnlyCollection<ResourceDescriptor>> _resourceDescriptorsPerAssembly =
new Dictionary<Assembly, IReadOnlyCollection<ResourceDescriptor>>();
private readonly TypeLocator _typeLocator = new();
private readonly Dictionary<Assembly, IReadOnlyCollection<ResourceDescriptor>> _resourceDescriptorsPerAssembly = new();

public void RegisterAssembly(Assembly assembly)
{
Expand Down
6 changes: 3 additions & 3 deletions src/JsonApiDotNetCore/Configuration/ResourceGraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ResourceGraphBuilder
{
private readonly IJsonApiOptions _options;
private readonly ILogger<ResourceGraphBuilder> _logger;
private readonly List<ResourceContext> _resources = new List<ResourceContext>();
private readonly TypeLocator _typeLocator = new TypeLocator();
private readonly List<ResourceContext> _resources = new();
private readonly TypeLocator _typeLocator = new();

public ResourceGraphBuilder(IJsonApiOptions options, ILoggerFactory loggerFactory)
{
Expand Down Expand Up @@ -126,7 +126,7 @@ public ResourceGraphBuilder Add(Type resourceType, Type idType = null, string pu

private ResourceContext CreateResourceContext(string publicName, Type resourceType, Type idType)
{
return new ResourceContext
return new()
{
PublicName = publicName,
ResourceType = resourceType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace JsonApiDotNetCore.Configuration
[PublicAPI]
public static class ServiceCollectionExtensions
{
private static readonly TypeLocator TypeLocator = new TypeLocator();
private static readonly TypeLocator TypeLocator = new();

/// <summary>
/// Configures JsonApiDotNetCore by registering resources manually.
Expand Down
10 changes: 5 additions & 5 deletions src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace JsonApiDotNetCore.Configuration
[PublicAPI]
public class ServiceDiscoveryFacade
{
internal static readonly HashSet<Type> ServiceInterfaces = new HashSet<Type>
internal static readonly HashSet<Type> ServiceInterfaces = new()
{
typeof(IResourceService<>),
typeof(IResourceService<,>),
Expand Down Expand Up @@ -47,7 +47,7 @@ public class ServiceDiscoveryFacade
typeof(IRemoveFromRelationshipService<,>)
};

internal static readonly HashSet<Type> RepositoryInterfaces = new HashSet<Type>
internal static readonly HashSet<Type> RepositoryInterfaces = new()
{
typeof(IResourceRepository<>),
typeof(IResourceRepository<,>),
Expand All @@ -57,7 +57,7 @@ public class ServiceDiscoveryFacade
typeof(IResourceReadRepository<,>)
};

internal static readonly HashSet<Type> ResourceDefinitionInterfaces = new HashSet<Type>
internal static readonly HashSet<Type> ResourceDefinitionInterfaces = new()
{
typeof(IResourceDefinition<>),
typeof(IResourceDefinition<,>)
Expand All @@ -67,8 +67,8 @@ public class ServiceDiscoveryFacade
private readonly IServiceCollection _services;
private readonly ResourceGraphBuilder _resourceGraphBuilder;
private readonly IJsonApiOptions _options;
private readonly ResourceDescriptorAssemblyCache _assemblyCache = new ResourceDescriptorAssemblyCache();
private readonly TypeLocator _typeLocator = new TypeLocator();
private readonly ResourceDescriptorAssemblyCache _assemblyCache = new();
private readonly TypeLocator _typeLocator = new();

public ServiceDiscoveryFacade(IServiceCollection services, ResourceGraphBuilder resourceGraphBuilder, IJsonApiOptions options,
ILoggerFactory loggerFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace JsonApiDotNetCore.Controllers.Annotations
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface)]
public sealed class DisableQueryStringAttribute : Attribute
{
public static readonly DisableQueryStringAttribute Empty = new DisableQueryStringAttribute(StandardQueryStringParameters.None);
public static readonly DisableQueryStringAttribute Empty = new(StandardQueryStringParameters.None);
public IReadOnlyCollection<string> ParameterNames { get; }

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public virtual async Task<IActionResult> PatchAsync(TId id, [FromBody] TResource
}

TResource updated = await _update.UpdateAsync(id, resource, cancellationToken);
return updated == null ? (IActionResult)NoContent() : Ok(updated);
return updated == null ? NoContent() : Ok(updated);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public virtual async Task<IActionResult> PostOperationsAsync([FromBody] IList<Op
}

IList<OperationContainer> results = await _processor.ProcessAsync(operations, cancellationToken);
return results.Any(result => result != null) ? (IActionResult)Ok(results) : NoContent();
return results.Any(result => result != null) ? Ok(results) : NoContent();
}

protected virtual void ValidateClientGeneratedIds(IEnumerable<OperationContainer> operations)
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/Errors/JsonApiException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace JsonApiDotNetCore.Errors
[PublicAPI]
public class JsonApiException : Exception
{
private static readonly JsonSerializerSettings ErrorSerializerSettings = new JsonSerializerSettings
private static readonly JsonSerializerSettings ErrorSerializerSettings = new()
{
NullValueHandling = NullValueHandling.Ignore,
Formatting = Formatting.Indented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ResourcesInRelationshipsNotFoundException(IEnumerable<MissingResourceInRe

private static Error CreateError(MissingResourceInRelationship missingResourceInRelationship)
{
return new Error(HttpStatusCode.NotFound)
return new(HttpStatusCode.NotFound)
{
Title = "A related resource does not exist.",
Detail = $"Related resource of type '{missingResourceInRelationship.ResourceType}' with ID '{missingResourceInRelationship.ResourceId}' " +
Expand Down
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/JsonApiDotNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<ItemGroup>
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
<PackageReference Include="Humanizer" Version="2.11.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(EFCoreVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="$(EFCoreVersion)" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="SauceControl.InheritDoc" Version="1.3.0" PrivateAssets="All" />
Expand Down
11 changes: 9 additions & 2 deletions src/JsonApiDotNetCore/Middleware/FixedQueryFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public IQueryCollection Query
{
get
{
if (_features.Collection == null)
if (IsFeatureCollectionNull())
{
return _parsedValues ??= QueryCollection.Empty;
}
Expand All @@ -49,7 +49,7 @@ public IQueryCollection Query
{
_parsedValues = value;

if (_features.Collection != null)
if (!IsFeatureCollectionNull())
{
if (value == null)
{
Expand Down Expand Up @@ -77,5 +77,12 @@ public FixedQueryFeature(IFeatureCollection features)

_features.Initalize(features);
}

private bool IsFeatureCollectionNull()
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
// Justification: This code was copied from the ASP.NET sources. A struct instance can be created without calling one of its constructors.
return _features.Collection == null;
}
}
}
6 changes: 4 additions & 2 deletions src/JsonApiDotNetCore/Middleware/JsonApiMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ private static async Task<bool> ValidateContentTypeHeaderAsync(string allowedCon
{
string contentType = httpContext.Request.ContentType;

// ReSharper disable once ConditionIsAlwaysTrueOrFalse
// Justification: Workaround for https://github.com/dotnet/aspnetcore/issues/32097 (fixed in .NET 6)
if (contentType != null && contentType != allowedContentType)
{
await FlushResponseAsync(httpContext.Response, serializerSettings, new Error(HttpStatusCode.UnsupportedMediaType)
Expand Down Expand Up @@ -280,9 +282,9 @@ private static string GetCustomRoute(string resourceName, string apiNamespace, H
if (resourceName != null)
{
Endpoint endpoint = httpContext.GetEndpoint();
var routeAttribute = endpoint.Metadata.GetMetadata<RouteAttribute>();
var routeAttribute = endpoint?.Metadata.GetMetadata<RouteAttribute>();

if (routeAttribute != null)
if (routeAttribute != null && httpContext.Request.Path.Value != null)
{
List<string> trimmedComponents = httpContext.Request.Path.Value.Trim('/').Split('/').ToList();
int resourceNameIndex = trimmedComponents.FindIndex(component => component == resourceName);
Expand Down
6 changes: 3 additions & 3 deletions src/JsonApiDotNetCore/Middleware/JsonApiRoutingConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class JsonApiRoutingConvention : IJsonApiRoutingConvention
{
private readonly IJsonApiOptions _options;
private readonly IResourceContextProvider _resourceContextProvider;
private readonly Dictionary<string, string> _registeredControllerNameByTemplate = new Dictionary<string, string>();
private readonly Dictionary<Type, ResourceContext> _resourceContextPerControllerTypeMap = new Dictionary<Type, ResourceContext>();
private readonly Dictionary<ResourceContext, ControllerModel> _controllerPerResourceContextMap = new Dictionary<ResourceContext, ControllerModel>();
private readonly Dictionary<string, string> _registeredControllerNameByTemplate = new();
private readonly Dictionary<Type, ResourceContext> _resourceContextPerControllerTypeMap = new();
private readonly Dictionary<ResourceContext, ControllerModel> _controllerPerResourceContextMap = new();

public JsonApiRoutingConvention(IJsonApiOptions options, IResourceContextProvider resourceContextProvider)
{
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static T[] AsArray<T>(this T element)

public static List<T> AsList<T>(this T element)
{
return new List<T>
return new()
{
element
};
Expand Down
Loading