Skip to content

Commit 6f72110

Browse files
author
Bart Koelman
authored
Public API surface (#808)
* Renamed generic type parameter T to TResource * Fixed inconsistencies in generic type parameter constraints * Reviewed collection usage Reviewed generic IEnumerable usage in public signatures (fixes 'Possible multiple enumeration' warning) Reviewed usage of generic List and Dictionary in public signatures Removed redundant ToList/ToArray/AsReadOnly calls Replaced ToList() with ToArray(), which uses a bit more memory but is faster * Renamed CurrentRequest to JsonApiRequest ('current' is vague terminology) * Merged AssemblyInfo.cs versions and removed unneeded InternalsVisibleTo * Reorganized namespaces Moved types into separate files (and fixed filename mismatches) Unified TypeHelper and TypeExtensions (inlined methods with single usage) * Fixes in documentation generation. Removed the parts from .csproj because it does not work correctly -- it looks like something from before moving to /docs. * Code cleanup: removed redundant parentheses * Code cleanup: spelling errors * Code cleanup: removed redundant qualifiers * Code cleanup: removed redundant cast * Fixed: possible comparison of value type with null Removed invalid inheritdoc * Fixup naming conventions to match with existing style Culture-sensitive string comparions * Use null instead of empty string for default value of TId; removed hack for GUIDs * Renamed IJsonApiOptions parameter on controllers for consistency with other places * Trace logging: shorter syntax and improved performance * Added null checks on input parameters of exposed methods * Removed invalid usage of inheritdoc * Opened up more for extensibility * Extract method * Normalized spacing in inheritdoc tags * Reviewed doc-comments * Moved controller attributes in sub-namespace * Cleanup usings * Moved client serialization into Internal sub-namespace
1 parent 86de280 commit 6f72110

File tree

525 files changed

+5915
-5243
lines changed

Some content is hidden

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

525 files changed

+5915
-5243
lines changed

Directory.Build.props

+1-1
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,6 +9,7 @@
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 -->

README.md

+2-2
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
```

benchmarks/BenchmarkResource.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using JsonApiDotNetCore.Models;
2-
using JsonApiDotNetCore.Models.Annotation;
1+
using JsonApiDotNetCore.Resources;
2+
using JsonApiDotNetCore.Resources.Annotations;
33

44
namespace Benchmarks
55
{
66
public sealed class BenchmarkResource : Identifiable
77
{
8-
[Attr(BenchmarkResourcePublicNames.NameAttr)]
8+
[Attr(PublicName = BenchmarkResourcePublicNames.NameAttr)]
99
public string Name { get; set; }
1010

1111
[HasOne]

benchmarks/DependencyFactory.cs

+2-5
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.Services.Contract;
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using BenchmarkDotNet.Attributes;
21
using System;
32
using System.Text;
3+
using BenchmarkDotNet.Attributes;
44

55
namespace Benchmarks.LinkBuilder
66
{

benchmarks/Query/QueryParserBenchmarks.cs

+13-15
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.Internal.QueryStrings;
6+
using JsonApiDotNetCore.Middleware;
97
using JsonApiDotNetCore.QueryStrings;
10-
using JsonApiDotNetCore.RequestServices;
8+
using JsonApiDotNetCore.QueryStrings.Internal;
9+
using JsonApiDotNetCore.Resources;
1110
using Microsoft.AspNetCore.Http;
1211
using Microsoft.AspNetCore.WebUtilities;
1312
using Microsoft.Extensions.Logging.Abstractions;
@@ -30,20 +29,19 @@ public QueryParserBenchmarks()
3029

3130
IResourceGraph resourceGraph = DependencyFactory.CreateResourceGraph(options);
3231

33-
var currentRequest = new CurrentRequest
32+
var request = new JsonApiRequest
3433
{
3534
PrimaryResource = resourceGraph.GetResourceContext(typeof(BenchmarkResource))
3635
};
3736

38-
_queryStringReaderForSort = CreateQueryParameterDiscoveryForSort(resourceGraph, currentRequest, options, _queryStringAccessor);
39-
_queryStringReaderForAll = CreateQueryParameterDiscoveryForAll(resourceGraph, currentRequest, options, _queryStringAccessor);
37+
_queryStringReaderForSort = CreateQueryParameterDiscoveryForSort(resourceGraph, request, options, _queryStringAccessor);
38+
_queryStringReaderForAll = CreateQueryParameterDiscoveryForAll(resourceGraph, request, options, _queryStringAccessor);
4039
}
4140

4241
private static QueryStringReader CreateQueryParameterDiscoveryForSort(IResourceGraph resourceGraph,
43-
CurrentRequest currentRequest,
44-
IJsonApiOptions options, FakeRequestQueryStringAccessor queryStringAccessor)
42+
JsonApiRequest request, IJsonApiOptions options, FakeRequestQueryStringAccessor queryStringAccessor)
4543
{
46-
var sortReader = new SortQueryStringParameterReader(currentRequest, resourceGraph);
44+
var sortReader = new SortQueryStringParameterReader(request, resourceGraph);
4745

4846
var readers = new List<IQueryStringParameterReader>
4947
{
@@ -54,14 +52,14 @@ private static QueryStringReader CreateQueryParameterDiscoveryForSort(IResourceG
5452
}
5553

5654
private static QueryStringReader CreateQueryParameterDiscoveryForAll(IResourceGraph resourceGraph,
57-
CurrentRequest currentRequest, IJsonApiOptions options, FakeRequestQueryStringAccessor queryStringAccessor)
55+
JsonApiRequest request, IJsonApiOptions options, FakeRequestQueryStringAccessor queryStringAccessor)
5856
{
5957
var resourceFactory = new ResourceFactory(new ServiceContainer());
6058

61-
var filterReader = new FilterQueryStringParameterReader(currentRequest, resourceGraph, resourceFactory, options);
62-
var sortReader = new SortQueryStringParameterReader(currentRequest, resourceGraph);
63-
var sparseFieldSetReader = new SparseFieldSetQueryStringParameterReader(currentRequest, resourceGraph);
64-
var paginationReader = new PaginationQueryStringParameterReader(currentRequest, resourceGraph, options);
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);
6563
var defaultsReader = new DefaultsQueryStringParameterReader(options);
6664
var nullsReader = new NullsQueryStringParameterReader(options);
6765

benchmarks/Serialization/JsonApiDeserializerBenchmarks.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
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;
119
using Microsoft.AspNetCore.Http;
1210
using Newtonsoft.Json;
1311

benchmarks/Serialization/JsonApiSerializerBenchmarks.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
using System;
22
using BenchmarkDotNet.Attributes;
33
using JsonApiDotNetCore.Configuration;
4-
using JsonApiDotNetCore.Internal.Contracts;
5-
using JsonApiDotNetCore.Internal.QueryStrings;
4+
using JsonApiDotNetCore.Middleware;
65
using JsonApiDotNetCore.Queries;
7-
using JsonApiDotNetCore.RequestServices;
6+
using JsonApiDotNetCore.QueryStrings.Internal;
87
using JsonApiDotNetCore.Serialization;
9-
using JsonApiDotNetCore.Serialization.Server;
10-
using JsonApiDotNetCore.Serialization.Server.Builders;
8+
using JsonApiDotNetCore.Serialization.Building;
119
using Moq;
1210

1311
namespace Benchmarks.Serialization
@@ -41,11 +39,11 @@ public JsonApiSerializerBenchmarks()
4139

4240
private static FieldsToSerialize CreateFieldsToSerialize(IResourceGraph resourceGraph)
4341
{
44-
var currentRequest = new CurrentRequest();
42+
var request = new JsonApiRequest();
4543

4644
var constraintProviders = new IQueryConstraintProvider[]
4745
{
48-
new SparseFieldSetQueryStringParameterReader(currentRequest, resourceGraph)
46+
new SparseFieldSetQueryStringParameterReader(request, resourceGraph)
4947
};
5048

5149
var resourceDefinitionProvider = DependencyFactory.CreateResourceDefinitionProvider(resourceGraph);

docs/api/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ This section documents the package API and is generated from the XML source comm
55
## Common APIs
66

77
- [`JsonApiOptions`](JsonApiDotNetCore.Configuration.JsonApiOptions.yml)
8-
- [`IResourceGraph`](JsonApiDotNetCore.Internal.Contracts.IResourceGraph.yml)
9-
- [`ResourceDefinition<TResource>`](JsonApiDotNetCore.Models.ResourceDefinition-1.yml)
8+
- [`IResourceGraph`](JsonApiDotNetCore.Configuration.IResourceGraph.yml)
9+
- [`ResourceDefinition<TResource>`](JsonApiDotNetCore.Resources.ResourceDefinition-1.yml)

docs/docfx.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"dest": "api",
1111
"disableGitFeatures": false,
1212
"properties": {
13-
"targetFramework": "netstandard2.0"
13+
"targetFramework": "netcoreapp3.1"
1414
}
1515
}
1616
],

docs/getting-started/step-by-step.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ where `T` is the model that inherits from `Identifiable<TId>`
6868
public class PeopleController : JsonApiController<Person>
6969
{
7070
public PeopleController(
71-
IJsonApiOptions jsonApiOptions,
71+
IJsonApiOptions options,
7272
ILoggerFactory loggerFactory,
7373
IResourceService<Person> resourceService)
74-
: base(jsonApiOptions, loggerFactory, resourceService)
74+
: base(options, loggerFactory, resourceService)
7575
{ }
7676
}
7777
```

docs/usage/extensibility/controllers.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ You need to create controllers that inherit from `JsonApiController<T>`
66
public class ArticlesController : JsonApiController<Article>
77
{
88
public ArticlesController(
9-
IJsonApiOptions jsonApiOptions,
9+
IJsonApiOptions options,
1010
ILoggerFactory loggerFactory,
1111
IResourceService<Article> resourceService)
12-
: base(jsonApiOptions, loggerFactory, resourceService)
12+
: base(options, loggerFactory, resourceService)
1313
{ }
1414
}
1515
```
@@ -23,11 +23,11 @@ public class ArticlesController : JsonApiController<Article, Guid>
2323
//---------------------------------------------------------- ^^^^
2424
{
2525
public ArticlesController(
26-
IJsonApiOptions jsonApiOptions,
26+
IJsonApiOptions options,
2727
ILoggerFactory loggerFactory,
2828
IResourceService<Article, Guid> resourceService)
2929
//----------------------- ^^^^
30-
: base(jsonApiOptions, loggerFactory, resourceService)
30+
: base(options, loggerFactory, resourceService)
3131
{ }
3232
}
3333
```
@@ -44,10 +44,10 @@ This approach is ok, but introduces some boilerplate that can easily be avoided.
4444
public class ArticlesController : BaseJsonApiController<Article>
4545
{
4646
public ArticlesController(
47-
IJsonApiOptions jsonApiOptions,
47+
IJsonApiOptions options,
4848
ILoggerFactory loggerFactory,
4949
IResourceService<Article> resourceService)
50-
: base(jsonApiOptions, loggerFactory, resourceService)
50+
: base(options, loggerFactory, resourceService)
5151
{ }
5252

5353
[HttpGet]
@@ -81,10 +81,10 @@ An attempt to use one blacklisted methods will result in a HTTP 405 Method Not A
8181
public class ArticlesController : BaseJsonApiController<Article>
8282
{
8383
public ArticlesController(
84-
IJsonApiOptions jsonApiOptions,
84+
IJsonApiOptions options,
8585
ILoggerFactory loggerFactory,
8686
IResourceService<Article> resourceService)
87-
: base(jsonApiOptions, loggerFactory, resourceService)
87+
: base(options, loggerFactory, resourceService)
8888
{ }
8989
}
9090
```
@@ -101,10 +101,10 @@ For more information about resource injection, see the next section titled Resou
101101
public class ReportsController : BaseJsonApiController<Report>
102102
{
103103
public ReportsController(
104-
IJsonApiOptions jsonApiOptions,
104+
IJsonApiOptions options,
105105
ILoggerFactory loggerFactory,
106106
IResourceService<Report> resourceService)
107-
: base(jsonApiOptions, loggerFactory, resourceService)
107+
: base(options, loggerFactory, resourceService)
108108
{ }
109109

110110
[HttpGet]

docs/usage/extensibility/services.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ Then in the controller, you should inherit from the base controller and pass the
148148
public class ArticlesController : BaseJsonApiController<Article>
149149
{
150150
public ArticlesController(
151-
IJsonApiOptions jsonApiOptions,
151+
IJsonApiOptions options,
152152
ILoggerFactory loggerFactory,
153153
ICreateService<Article, int> create,
154154
IDeleteService<Article, int> delete)
155-
: base(jsonApiOptions, loggerFactory, create: create, delete: delete)
155+
: base(options, loggerFactory, create: create, delete: delete)
156156
{ }
157157

158158
[HttpPost]

docs/usage/routing.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ You can disable the default casing convention and specify your own template by u
3030
public class CamelCasedModelsController : JsonApiController<CamelCasedModel>
3131
{
3232
public CamelCasedModelsController(
33-
IJsonApiOptions jsonApiOptions,
33+
IJsonApiOptions options,
3434
ILoggerFactory loggerFactory,
3535
IResourceService<CamelCasedModel> resourceService)
36-
: base(jsonApiOptions, loggerFactory, resourceService)
36+
: base(options, loggerFactory, resourceService)
3737
{ }
3838
}
3939
```

src/Examples/GettingStarted/Controllers/ArticlesController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace GettingStarted.Controllers
99
public sealed class ArticlesController : JsonApiController<Article>
1010
{
1111
public ArticlesController(
12-
IJsonApiOptions jsonApiOptions,
12+
IJsonApiOptions options,
1313
ILoggerFactory loggerFactory,
1414
IResourceService<Article> resourceService)
15-
: base(jsonApiOptions, loggerFactory, resourceService)
15+
: base(options, loggerFactory, resourceService)
1616
{ }
1717
}
1818
}

src/Examples/GettingStarted/Controllers/PeopleController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace GettingStarted.Controllers
99
public sealed class PeopleController : JsonApiController<Person>
1010
{
1111
public PeopleController(
12-
IJsonApiOptions jsonApiOptions,
12+
IJsonApiOptions options,
1313
ILoggerFactory loggerFactory,
1414
IResourceService<Person> resourceService)
15-
: base(jsonApiOptions, loggerFactory, resourceService)
15+
: base(options, loggerFactory, resourceService)
1616
{ }
1717
}
1818
}

src/Examples/GettingStarted/Models/Article.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using JsonApiDotNetCore.Models;
2-
using JsonApiDotNetCore.Models.Annotation;
1+
using JsonApiDotNetCore.Resources;
2+
using JsonApiDotNetCore.Resources.Annotations;
33

44
namespace GettingStarted.Models
55
{

src/Examples/GettingStarted/Models/Person.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Collections.Generic;
2-
using JsonApiDotNetCore.Models;
3-
using JsonApiDotNetCore.Models.Annotation;
2+
using JsonApiDotNetCore.Resources;
3+
using JsonApiDotNetCore.Resources.Annotations;
44

55
namespace GettingStarted.Models
66
{

src/Examples/GettingStarted/Startup.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using GettingStarted.Data;
22
using GettingStarted.Models;
3-
using JsonApiDotNetCore;
3+
using JsonApiDotNetCore.Configuration;
44
using Microsoft.AspNetCore.Builder;
55
using Microsoft.EntityFrameworkCore;
66
using Microsoft.Extensions.DependencyInjection;

src/Examples/JsonApiDotNetCoreExample/Controllers/ArticlesController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace JsonApiDotNetCoreExample.Controllers
99
public sealed class ArticlesController : JsonApiController<Article>
1010
{
1111
public ArticlesController(
12-
IJsonApiOptions jsonApiOptions,
12+
IJsonApiOptions options,
1313
ILoggerFactory loggerFactory,
1414
IResourceService<Article> resourceService)
15-
: base(jsonApiOptions, loggerFactory, resourceService)
15+
: base(options, loggerFactory, resourceService)
1616
{ }
1717
}
1818
}

src/Examples/JsonApiDotNetCoreExample/Controllers/AuthorsController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace JsonApiDotNetCoreExample.Controllers
99
public sealed class AuthorsController : JsonApiController<Author>
1010
{
1111
public AuthorsController(
12-
IJsonApiOptions jsonApiOptions,
12+
IJsonApiOptions options,
1313
ILoggerFactory loggerFactory,
1414
IResourceService<Author> resourceService)
15-
: base(jsonApiOptions, loggerFactory, resourceService)
15+
: base(options, loggerFactory, resourceService)
1616
{ }
1717
}
1818
}

src/Examples/JsonApiDotNetCoreExample/Controllers/BlogsController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace JsonApiDotNetCoreExample.Controllers
99
public sealed class BlogsController : JsonApiController<Blog>
1010
{
1111
public BlogsController(
12-
IJsonApiOptions jsonApiOptions,
12+
IJsonApiOptions options,
1313
ILoggerFactory loggerFactory,
1414
IResourceService<Blog> resourceService)
15-
: base(jsonApiOptions, loggerFactory, resourceService)
15+
: base(options, loggerFactory, resourceService)
1616
{ }
1717
}
1818
}

0 commit comments

Comments
 (0)