Skip to content

Commit 27f31be

Browse files
committed
chore: review
1 parent 8831ce2 commit 27f31be

File tree

674 files changed

+24782
-15523
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

674 files changed

+24782
-15523
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ StyleCopReport.xml
9797
*.svclog
9898
*.scc
9999

100+
# MacOS file systems
101+
**/.DS_STORE
102+
100103
# Chutzpah Test files
101104
_Chutzpah*
102105

@@ -131,6 +134,9 @@ _ReSharper*/
131134
*.[Rr]e[Ss]harper
132135
*.DotSettings.user
133136

137+
# JetBrains Rider
138+
.idea/
139+
134140
# TeamCity is a build add-in
135141
_TeamCity*
136142

Build.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,19 @@ If($env:APPVEYOR_REPO_TAG -eq $true) {
3838

3939
IF ([string]::IsNullOrWhitespace($revision)){
4040
Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts"
41-
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --include-symbols
41+
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts
4242
CheckLastExitCode
4343
}
4444
Else {
4545
Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision"
46-
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision --include-symbols
46+
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision
4747
CheckLastExitCode
4848
}
4949
}
50-
Else {
51-
Write-Output "VERSION-SUFFIX: alpha5-$revision"
52-
Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision"
53-
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision --include-symbols
50+
Else {
51+
$packageVersionSuffix="alpha5-$revision"
52+
Write-Output "VERSION-SUFFIX: $packageVersionSuffix"
53+
Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$packageVersionSuffix"
54+
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$packageVersionSuffix
5455
CheckLastExitCode
5556
}

Directory.Build.props

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project>
22
<PropertyGroup>
33
<NetCoreAppVersion>netcoreapp3.1</NetCoreAppVersion>
4-
<NetStandardVersion>netstandard2.1</NetStandardVersion>
54
<AspNetCoreVersion>3.1.*</AspNetCoreVersion>
65
<EFCoreVersion>3.1.*</EFCoreVersion>
76
<NpgsqlPostgreSQLVersion>3.1.*</NpgsqlPostgreSQLVersion>
@@ -10,12 +9,14 @@
109
<PropertyGroup Condition="'$(Configuration)'=='Release'">
1110
<NoWarn>$(NoWarn);1591</NoWarn>
1211
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
12+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1313
</PropertyGroup>
1414

1515
<!-- Test Project Dependencies -->
1616
<PropertyGroup>
1717
<XUnitVersion>2.4.1</XUnitVersion>
18+
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>
1819
<BogusVersion>29.0.1</BogusVersion>
1920
<MoqVersion>4.13.1</MoqVersion>
2021
</PropertyGroup>
21-
</Project>
22+
</Project>

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public class Article : Identifiable
5454
public class ArticlesController : JsonApiController<Article>
5555
{
5656
public ArticlesController(
57-
IJsonApiOptions jsonApiOptions,
57+
IJsonApiOptions options,
5858
IResourceService<Article> resourceService,
5959
ILoggerFactory loggerFactory)
60-
: base(jsonApiOptions, resourceService, loggerFactory)
60+
: base(options, resourceService, loggerFactory)
6161
{ }
6262
}
6363
```
@@ -121,3 +121,15 @@ A lot of changes were introduced in v4.0.0, the following chart should help you
121121
| ----------------- | ------------- |
122122
| 2.* | v3.* |
123123
| 3.* | v4.* |
124+
125+
## Trying out the latest build
126+
127+
After each commit, a new prerelease NuGet package is automatically published to AppVeyor at https://ci.appveyor.com/nuget/jsonapidotnetcore. To try it out, follow the next steps:
128+
129+
* In Visual Studio: **Tools**, **NuGet Package Manager**, **Package Manager Settings**, **Package Sources**
130+
* Click **+**
131+
* Name: **AppVeyor JADNC**, Source: **https://ci.appveyor.com/nuget/jsonapidotnetcore**
132+
* Click **Update**, **Ok**
133+
* Open the NuGet package manager console (**Tools**, **NuGet Package Manager**, **Package Manager Console**)
134+
* Select **AppVeyor JADNC** as package source
135+
* Run command: `Install-Package JonApiDotNetCore -pre`

benchmarks/BenchmarkResource.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using JsonApiDotNetCore.Models;
1+
using JsonApiDotNetCore.Resources;
2+
using JsonApiDotNetCore.Resources.Annotations;
23

34
namespace Benchmarks
45
{
56
public sealed class BenchmarkResource : Identifiable
67
{
7-
[Attr(BenchmarkResourcePublicNames.NameAttr)]
8+
[Attr(PublicName = BenchmarkResourcePublicNames.NameAttr)]
89
public string Name { get; set; }
910

1011
[HasOne]

benchmarks/DependencyFactory.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
2-
using JsonApiDotNetCore.Builders;
32
using JsonApiDotNetCore.Configuration;
4-
using JsonApiDotNetCore.Internal.Contracts;
5-
using JsonApiDotNetCore.Models;
6-
using JsonApiDotNetCore.Query;
3+
using JsonApiDotNetCore.Resources;
74
using Microsoft.Extensions.Logging.Abstractions;
85
using Moq;
96

@@ -14,7 +11,7 @@ internal static class DependencyFactory
1411
public static IResourceGraph CreateResourceGraph(IJsonApiOptions options)
1512
{
1613
IResourceGraphBuilder builder = new ResourceGraphBuilder(options, NullLoggerFactory.Instance);
17-
builder.AddResource<BenchmarkResource>(BenchmarkResourcePublicNames.Type);
14+
builder.Add<BenchmarkResource>(BenchmarkResourcePublicNames.Type);
1815
return builder.Build();
1916
}
2017

benchmarks/LinkBuilder/LinkBuilderGetNamespaceFromPathBenchmarks.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
using BenchmarkDotNet.Attributes;
21
using System;
32
using System.Text;
3+
using BenchmarkDotNet.Attributes;
44

55
namespace Benchmarks.LinkBuilder
66
{
77
[MarkdownExporter, SimpleJob(launchCount: 3, warmupCount: 10, targetCount: 20), MemoryDiagnoser]
88
public class LinkBuilderGetNamespaceFromPathBenchmarks
99
{
1010
private const string RequestPath = "/api/some-really-long-namespace-path/resources/current/articles/?some";
11-
private const string EntityName = "articles";
11+
private const string ResourceName = "articles";
1212
private const char PathDelimiter = '/';
1313

1414
[Benchmark]
15-
public void UsingStringSplit() => GetNamespaceFromPathUsingStringSplit(RequestPath, EntityName);
15+
public void UsingStringSplit() => GetNamespaceFromPathUsingStringSplit(RequestPath, ResourceName);
1616

1717
[Benchmark]
18-
public void UsingReadOnlySpan() => GetNamespaceFromPathUsingReadOnlySpan(RequestPath, EntityName);
18+
public void UsingReadOnlySpan() => GetNamespaceFromPathUsingReadOnlySpan(RequestPath, ResourceName);
1919

20-
public static string GetNamespaceFromPathUsingStringSplit(string path, string entityName)
20+
public static string GetNamespaceFromPathUsingStringSplit(string path, string resourceName)
2121
{
2222
StringBuilder namespaceBuilder = new StringBuilder(path.Length);
2323
string[] segments = path.Split('/');
2424

2525
for (int index = 1; index < segments.Length; index++)
2626
{
27-
if (segments[index] == entityName)
27+
if (segments[index] == resourceName)
2828
{
2929
break;
3030
}
@@ -36,22 +36,22 @@ public static string GetNamespaceFromPathUsingStringSplit(string path, string en
3636
return namespaceBuilder.ToString();
3737
}
3838

39-
public static string GetNamespaceFromPathUsingReadOnlySpan(string path, string entityName)
39+
public static string GetNamespaceFromPathUsingReadOnlySpan(string path, string resourceName)
4040
{
41-
ReadOnlySpan<char> entityNameSpan = entityName.AsSpan();
41+
ReadOnlySpan<char> resourceNameSpan = resourceName.AsSpan();
4242
ReadOnlySpan<char> pathSpan = path.AsSpan();
4343

4444
for (int index = 0; index < pathSpan.Length; index++)
4545
{
4646
if (pathSpan[index].Equals(PathDelimiter))
4747
{
48-
if (pathSpan.Length > index + entityNameSpan.Length)
48+
if (pathSpan.Length > index + resourceNameSpan.Length)
4949
{
50-
ReadOnlySpan<char> possiblePathSegment = pathSpan.Slice(index + 1, entityNameSpan.Length);
50+
ReadOnlySpan<char> possiblePathSegment = pathSpan.Slice(index + 1, resourceNameSpan.Length);
5151

52-
if (entityNameSpan.SequenceEqual(possiblePathSegment))
52+
if (resourceNameSpan.SequenceEqual(possiblePathSegment))
5353
{
54-
int lastCharacterIndex = index + 1 + entityNameSpan.Length;
54+
int lastCharacterIndex = index + 1 + resourceNameSpan.Length;
5555

5656
bool isAtEnd = lastCharacterIndex == pathSpan.Length;
5757
bool hasDelimiterAfterSegment = pathSpan.Length >= lastCharacterIndex + 1 && pathSpan[lastCharacterIndex].Equals(PathDelimiter);

benchmarks/Query/QueryParserBenchmarks.cs

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.Design;
34
using BenchmarkDotNet.Attributes;
45
using JsonApiDotNetCore.Configuration;
5-
using JsonApiDotNetCore.Internal.Contracts;
6-
using JsonApiDotNetCore.Managers;
7-
using JsonApiDotNetCore.Query;
8-
using JsonApiDotNetCore.QueryParameterServices.Common;
9-
using JsonApiDotNetCore.Services;
6+
using JsonApiDotNetCore.Middleware;
7+
using JsonApiDotNetCore.QueryStrings;
8+
using JsonApiDotNetCore.QueryStrings.Internal;
9+
using JsonApiDotNetCore.Resources;
1010
using Microsoft.AspNetCore.Http;
1111
using Microsoft.AspNetCore.WebUtilities;
1212
using Microsoft.Extensions.Logging.Abstractions;
@@ -17,56 +17,58 @@ namespace Benchmarks.Query
1717
public class QueryParserBenchmarks
1818
{
1919
private readonly FakeRequestQueryStringAccessor _queryStringAccessor = new FakeRequestQueryStringAccessor();
20-
private readonly QueryParameterParser _queryParameterParserForSort;
21-
private readonly QueryParameterParser _queryParameterParserForAll;
20+
private readonly QueryStringReader _queryStringReaderForSort;
21+
private readonly QueryStringReader _queryStringReaderForAll;
2222

2323
public QueryParserBenchmarks()
2424
{
25-
IJsonApiOptions options = new JsonApiOptions();
25+
IJsonApiOptions options = new JsonApiOptions
26+
{
27+
EnableLegacyFilterNotation = true
28+
};
29+
2630
IResourceGraph resourceGraph = DependencyFactory.CreateResourceGraph(options);
27-
28-
var currentRequest = new CurrentRequest();
29-
currentRequest.SetRequestResource(resourceGraph.GetResourceContext(typeof(BenchmarkResource)));
3031

31-
IResourceDefinitionProvider resourceDefinitionProvider = DependencyFactory.CreateResourceDefinitionProvider(resourceGraph);
32+
var request = new JsonApiRequest
33+
{
34+
PrimaryResource = resourceGraph.GetResourceContext(typeof(BenchmarkResource))
35+
};
3236

33-
_queryParameterParserForSort = CreateQueryParameterDiscoveryForSort(resourceGraph, currentRequest, resourceDefinitionProvider, options, _queryStringAccessor);
34-
_queryParameterParserForAll = CreateQueryParameterDiscoveryForAll(resourceGraph, currentRequest, resourceDefinitionProvider, options, _queryStringAccessor);
37+
_queryStringReaderForSort = CreateQueryParameterDiscoveryForSort(resourceGraph, request, options, _queryStringAccessor);
38+
_queryStringReaderForAll = CreateQueryParameterDiscoveryForAll(resourceGraph, request, options, _queryStringAccessor);
3539
}
3640

37-
private static QueryParameterParser CreateQueryParameterDiscoveryForSort(IResourceGraph resourceGraph,
38-
CurrentRequest currentRequest, IResourceDefinitionProvider resourceDefinitionProvider,
39-
IJsonApiOptions options, FakeRequestQueryStringAccessor queryStringAccessor)
41+
private static QueryStringReader CreateQueryParameterDiscoveryForSort(IResourceGraph resourceGraph,
42+
JsonApiRequest request, IJsonApiOptions options, FakeRequestQueryStringAccessor queryStringAccessor)
4043
{
41-
ISortService sortService = new SortService(resourceDefinitionProvider, resourceGraph, currentRequest);
42-
43-
var queryServices = new List<IQueryParameterService>
44+
var sortReader = new SortQueryStringParameterReader(request, resourceGraph);
45+
46+
var readers = new List<IQueryStringParameterReader>
4447
{
45-
sortService
48+
sortReader
4649
};
4750

48-
return new QueryParameterParser(options, queryStringAccessor, queryServices, NullLoggerFactory.Instance);
51+
return new QueryStringReader(options, queryStringAccessor, readers, NullLoggerFactory.Instance);
4952
}
5053

51-
private static QueryParameterParser CreateQueryParameterDiscoveryForAll(IResourceGraph resourceGraph,
52-
CurrentRequest currentRequest, IResourceDefinitionProvider resourceDefinitionProvider,
53-
IJsonApiOptions options, FakeRequestQueryStringAccessor queryStringAccessor)
54+
private static QueryStringReader CreateQueryParameterDiscoveryForAll(IResourceGraph resourceGraph,
55+
JsonApiRequest request, IJsonApiOptions options, FakeRequestQueryStringAccessor queryStringAccessor)
5456
{
55-
IIncludeService includeService = new IncludeService(resourceGraph, currentRequest);
56-
IFilterService filterService = new FilterService(resourceDefinitionProvider, resourceGraph, currentRequest);
57-
ISortService sortService = new SortService(resourceDefinitionProvider, resourceGraph, currentRequest);
58-
ISparseFieldsService sparseFieldsService = new SparseFieldsService(resourceGraph, currentRequest);
59-
IPageService pageService = new PageService(options, resourceGraph, currentRequest);
60-
IDefaultsService defaultsService = new DefaultsService(options);
61-
INullsService nullsService = new NullsService(options);
62-
63-
var queryServices = new List<IQueryParameterService>
57+
var resourceFactory = new ResourceFactory(new ServiceContainer());
58+
59+
var filterReader = new FilterQueryStringParameterReader(request, resourceGraph, resourceFactory, options);
60+
var sortReader = new SortQueryStringParameterReader(request, resourceGraph);
61+
var sparseFieldSetReader = new SparseFieldSetQueryStringParameterReader(request, resourceGraph);
62+
var paginationReader = new PaginationQueryStringParameterReader(request, resourceGraph, options);
63+
var defaultsReader = new DefaultsQueryStringParameterReader(options);
64+
var nullsReader = new NullsQueryStringParameterReader(options);
65+
66+
var readers = new List<IQueryStringParameterReader>
6467
{
65-
includeService, filterService, sortService, sparseFieldsService, pageService, defaultsService,
66-
nullsService
68+
filterReader, sortReader, sparseFieldSetReader, paginationReader, defaultsReader, nullsReader
6769
};
6870

69-
return new QueryParameterParser(options, queryStringAccessor, queryServices, NullLoggerFactory.Instance);
71+
return new QueryStringReader(options, queryStringAccessor, readers, NullLoggerFactory.Instance);
7072
}
7173

7274
[Benchmark]
@@ -75,7 +77,7 @@ public void AscendingSort()
7577
var queryString = $"?sort={BenchmarkResourcePublicNames.NameAttr}";
7678

7779
_queryStringAccessor.SetQueryString(queryString);
78-
_queryParameterParserForSort.Parse(null);
80+
_queryStringReaderForSort.ReadAll(null);
7981
}
8082

8183
[Benchmark]
@@ -84,7 +86,7 @@ public void DescendingSort()
8486
var queryString = $"?sort=-{BenchmarkResourcePublicNames.NameAttr}";
8587

8688
_queryStringAccessor.SetQueryString(queryString);
87-
_queryParameterParserForSort.Parse(null);
89+
_queryStringReaderForSort.ReadAll(null);
8890
}
8991

9092
[Benchmark]
@@ -93,7 +95,7 @@ public void ComplexQuery() => Run(100, () =>
9395
var queryString = $"?filter[{BenchmarkResourcePublicNames.NameAttr}]=abc,eq:abc&sort=-{BenchmarkResourcePublicNames.NameAttr}&include=child&page[size]=1&fields={BenchmarkResourcePublicNames.NameAttr}";
9496

9597
_queryStringAccessor.SetQueryString(queryString);
96-
_queryParameterParserForAll.Parse(null);
98+
_queryStringReaderForAll.ReadAll(null);
9799
});
98100

99101
private void Run(int iterations, Action action) {

benchmarks/Serialization/JsonApiDeserializerBenchmarks.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
using System.ComponentModel.Design;
44
using BenchmarkDotNet.Attributes;
55
using JsonApiDotNetCore.Configuration;
6-
using JsonApiDotNetCore.Internal;
7-
using JsonApiDotNetCore.Internal.Contracts;
8-
using JsonApiDotNetCore.Models;
6+
using JsonApiDotNetCore.Resources;
97
using JsonApiDotNetCore.Serialization;
10-
using JsonApiDotNetCore.Serialization.Server;
8+
using JsonApiDotNetCore.Serialization.Objects;
9+
using Microsoft.AspNetCore.Http;
1110
using Newtonsoft.Json;
1211

1312
namespace Benchmarks.Serialization
@@ -38,8 +37,7 @@ public JsonApiDeserializerBenchmarks()
3837
var options = new JsonApiOptions();
3938
IResourceGraph resourceGraph = DependencyFactory.CreateResourceGraph(options);
4039
var targetedFields = new TargetedFields();
41-
42-
_jsonApiDeserializer = new RequestDeserializer(resourceGraph, new DefaultResourceFactory(new ServiceContainer()), targetedFields);
40+
_jsonApiDeserializer = new RequestDeserializer(resourceGraph, new ResourceFactory(new ServiceContainer()), targetedFields, new HttpContextAccessor());
4341
}
4442

4543
[Benchmark]

0 commit comments

Comments
 (0)