Skip to content

Commit

Permalink
Merge c6c2b74 into 6540c12
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Koelman authored Apr 21, 2021
2 parents 6540c12 + c6c2b74 commit bf241bd
Show file tree
Hide file tree
Showing 187 changed files with 415 additions and 438 deletions.
8 changes: 4 additions & 4 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>6.0.0-preview.3.21201.2</EFCoreVersion>
<NpgsqlPostgreSQLVersion>6.0.0-preview3</NpgsqlPostgreSQLVersion>
<CodeAnalysisRuleSet>$(SolutionDir)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ public ArticleHooksDefinition(IResourceGraph resourceGraph)

public override IEnumerable<Article> OnReturn(HashSet<Article> resources, ResourcePipeline pipeline)
{
if (pipeline == ResourcePipeline.GetSingle && resources.Any(article => article.Caption == "Classified"))
[AssertionMethod]
static bool Predicate(Article article)
{
return article.Caption == "Classified";
}

if (pipeline == ResourcePipeline.GetSingle && resources.Any(Predicate))
{
throw new JsonApiException(new Error(HttpStatusCode.Forbidden)
{
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 @@ -34,7 +34,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
8 changes: 2 additions & 6 deletions src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ public sealed class JsonApiOptions : IJsonApiOptions
{
internal static readonly NamingStrategy DefaultNamingStrategy = new CamelCaseNamingStrategy();

// Workaround for https://github.com/dotnet/efcore/issues/21026
internal bool DisableTopPagination { get; set; }
internal bool DisableChildrenPagination { get; set; }

/// <inheritdoc />
public string Namespace { get; set; }

Expand All @@ -41,7 +37,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 @@ -83,7 +79,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,9 @@ namespace JsonApiDotNetCore.Configuration
/// </summary>
internal sealed class ResourceDescriptorAssemblyCache
{
private readonly TypeLocator _typeLocator = new TypeLocator();
private readonly TypeLocator _typeLocator = new();

private readonly Dictionary<Assembly, IReadOnlyCollection<ResourceDescriptor>> _resourceDescriptorsPerAssembly =
new Dictionary<Assembly, IReadOnlyCollection<ResourceDescriptor>>();
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 @@ -16,7 +16,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 @@ -19,7 +19,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 @@ -49,7 +49,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 @@ -59,7 +59,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 @@ -69,8 +69,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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class DiffableResourceHashSet<TResource> : ResourceHashSet<TResour
where TResource : class, IIdentifiable
{
// ReSharper disable once StaticMemberInGenericType
private static readonly CollectionConverter CollectionConverter = new CollectionConverter();
private static readonly CollectionConverter CollectionConverter = new();

private readonly HashSet<TResource> _databaseValues;
private readonly bool _databaseValuesLoaded;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace JsonApiDotNetCore.Hooks.Internal.Execution
/// <inheritdoc />
internal sealed class HookContainerProvider : IHookContainerProvider
{
private static readonly HooksCollectionConverter CollectionConverter = new HooksCollectionConverter();
private static readonly HooksObjectFactory ObjectFactory = new HooksObjectFactory();
private static readonly IncludeChainConverter IncludeChainConverter = new IncludeChainConverter();
private static readonly HooksCollectionConverter CollectionConverter = new();
private static readonly HooksObjectFactory ObjectFactory = new();
private static readonly IncludeChainConverter IncludeChainConverter = new();

private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance;
private readonly IJsonApiOptions _options;
Expand Down
6 changes: 3 additions & 3 deletions src/JsonApiDotNetCore/Hooks/Internal/ResourceHookExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ namespace JsonApiDotNetCore.Hooks.Internal
/// <inheritdoc />
internal sealed class ResourceHookExecutor : IResourceHookExecutor
{
private static readonly IncludeChainConverter IncludeChainConverter = new IncludeChainConverter();
private static readonly HooksObjectFactory ObjectFactory = new HooksObjectFactory();
private static readonly HooksCollectionConverter CollectionConverter = new HooksCollectionConverter();
private static readonly IncludeChainConverter IncludeChainConverter = new();
private static readonly HooksObjectFactory ObjectFactory = new();
private static readonly HooksCollectionConverter CollectionConverter = new();

private readonly IHookContainerProvider _containerProvider;
private readonly INodeNavigator _nodeNavigator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace JsonApiDotNetCore.Hooks.Internal.Traversal
{
internal abstract class ChildNode
{
protected static readonly CollectionConverter CollectionConverter = new CollectionConverter();
protected static readonly CollectionConverter CollectionConverter = new();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace JsonApiDotNetCore.Hooks.Internal.Traversal
/// </summary>
internal sealed class NodeNavigator : INodeNavigator
{
private static readonly HooksObjectFactory ObjectFactory = new HooksObjectFactory();
private static readonly HooksCollectionConverter CollectionConverter = new HooksCollectionConverter();
private static readonly HooksObjectFactory ObjectFactory = new();
private static readonly HooksCollectionConverter CollectionConverter = new();

private readonly IdentifiableComparer _comparer = IdentifiableComparer.Instance;
private readonly IResourceGraph _resourceGraph;
Expand All @@ -27,7 +27,7 @@ internal sealed class NodeNavigator : INodeNavigator
/// <summary>
/// A mapper from <see cref="RelationshipAttribute" /> to <see cref="RelationshipProxy" />. See the latter for more details.
/// </summary>
private readonly Dictionary<RelationshipAttribute, RelationshipProxy> _relationshipProxies = new Dictionary<RelationshipAttribute, RelationshipProxy>();
private readonly Dictionary<RelationshipAttribute, RelationshipProxy> _relationshipProxies = new();

/// <summary>
/// Keeps track of which resources has already been traversed through, to prevent infinite loops in eg cyclic data structures.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace JsonApiDotNetCore.Hooks.Internal.Traversal
/// </summary>
internal sealed class RelationshipProxy
{
private static readonly HooksCollectionConverter CollectionConverter = new HooksCollectionConverter();
private static readonly HooksCollectionConverter CollectionConverter = new();

private readonly bool _skipThroughType;

Expand Down
3 changes: 2 additions & 1 deletion src/JsonApiDotNetCore/JsonApiDotNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<DebugType>embedded</DebugType>
<Version>4.1.1-pre</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -23,7 +24,7 @@
<ItemGroup>
<PackageReference Include="Ben.Demystifier" Version="0.3.0" />
<PackageReference Include="Humanizer" Version="2.8.26" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(EFCoreVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
Expand Down
5 changes: 3 additions & 2 deletions src/JsonApiDotNetCore/Middleware/JsonApiMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ private static async Task<bool> ValidateContentTypeHeaderAsync(string allowedCon
{
string contentType = httpContext.Request.ContentType;

// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (contentType != null && contentType != allowedContentType)
{
await FlushResponseAsync(httpContext.Response, serializerSettings, new Error(HttpStatusCode.UnsupportedMediaType)
Expand Down Expand Up @@ -257,11 +258,11 @@ 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)
{
List<string> trimmedComponents = httpContext.Request.Path.Value.Trim('/').Split('/').ToList();
List<string> trimmedComponents = httpContext.Request.Path.Value!.Trim('/').Split('/').ToList();
int resourceNameIndex = trimmedComponents.FindIndex(component => component == resourceName);
string[] newComponents = trimmedComponents.Take(resourceNameIndex).ToArray();
string customRoute = string.Join('/', newComponents);
Expand Down
Loading

0 comments on commit bf241bd

Please sign in to comment.