Skip to content

Commit 02f654c

Browse files
Replace int with long for ID (#1879)
* Replace int with long for resource identifiers in benchmarks * Replace int with long for resource identifiers across models and repositories * Refactor Identifiable base class to use long instead of int for ID types across various resource models and tests * Update documentation to use long instead of int for Identifiable types across various resource models * Refactor PrivateResourceRepository to maintain consistent formatting in constructor parameters * Update documentation to replace int with long --------- Co-authored-by: Nitesh Singhal <nitesh.singhal@siemens.com>
1 parent 1e207f5 commit 02f654c

File tree

143 files changed

+282
-282
lines changed

Some content is hidden

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

143 files changed

+282
-282
lines changed

benchmarks/Deserialization/DeserializationBenchmarkBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public abstract class DeserializationBenchmarkBase : IDisposable
2121
protected DeserializationBenchmarkBase()
2222
{
2323
var options = new JsonApiOptions();
24-
IResourceGraph resourceGraph = new ResourceGraphBuilder(options, NullLoggerFactory.Instance).Add<IncomingResource, int>().Build();
24+
IResourceGraph resourceGraph = new ResourceGraphBuilder(options, NullLoggerFactory.Instance).Add<IncomingResource, long>().Build();
2525
options.SerializerOptions.Converters.Add(new ResourceObjectConverter(resourceGraph));
2626
SerializerReadOptions = ((IJsonApiOptions)options).SerializerReadOptions;
2727

2828
var resourceFactory = new ResourceFactory(_serviceProvider);
2929
var resourceDefinitionAccessor = new ResourceDefinitionAccessor(resourceGraph, _serviceProvider);
3030

3131
_serviceProvider.AddService(typeof(IResourceDefinitionAccessor), resourceDefinitionAccessor);
32-
_serviceProvider.AddService(typeof(IResourceDefinition<IncomingResource, int>), new JsonApiResourceDefinition<IncomingResource, int>(resourceGraph));
32+
_serviceProvider.AddService(typeof(IResourceDefinition<IncomingResource, long>), new JsonApiResourceDefinition<IncomingResource, long>(resourceGraph));
3333

3434
// ReSharper disable once VirtualMemberCallInConstructor
3535
JsonApiRequest request = CreateJsonApiRequest(resourceGraph);
@@ -71,7 +71,7 @@ private void Dispose(bool disposing)
7171
}
7272

7373
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
74-
public sealed class IncomingResource : Identifiable<int>
74+
public sealed class IncomingResource : Identifiable<long>
7575
{
7676
[Attr]
7777
public bool Attribute01 { get; set; }

benchmarks/QueryString/QueryStringParserBenchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public QueryStringParserBenchmarks()
2727
EnableLegacyFilterNotation = true
2828
};
2929

30-
IResourceGraph resourceGraph = new ResourceGraphBuilder(options, NullLoggerFactory.Instance).Add<QueryableResource, int>("alt-resource-name").Build();
30+
IResourceGraph resourceGraph = new ResourceGraphBuilder(options, NullLoggerFactory.Instance).Add<QueryableResource, long>("alt-resource-name").Build();
3131

3232
var request = new JsonApiRequest
3333
{

benchmarks/QueryString/QueryableResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Benchmarks.QueryString;
66

77
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
8-
public sealed class QueryableResource : Identifiable<int>
8+
public sealed class QueryableResource : Identifiable<long>
99
{
1010
[Attr(PublicName = "alt-attr-name")]
1111
public string? Name { get; set; }

benchmarks/Serialization/SerializationBenchmarkBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected SerializationBenchmarkBase()
3131
}
3232
};
3333

34-
ResourceGraph = new ResourceGraphBuilder(options, NullLoggerFactory.Instance).Add<OutgoingResource, int>().Build();
34+
ResourceGraph = new ResourceGraphBuilder(options, NullLoggerFactory.Instance).Add<OutgoingResource, long>().Build();
3535
SerializerWriteOptions = ((IJsonApiOptions)options).SerializerWriteOptions;
3636

3737
// ReSharper disable VirtualMemberCallInConstructor
@@ -55,7 +55,7 @@ protected SerializationBenchmarkBase()
5555
protected abstract IEvaluatedIncludeCache CreateEvaluatedIncludeCache(IResourceGraph resourceGraph);
5656

5757
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
58-
public sealed class OutgoingResource : Identifiable<int>
58+
public sealed class OutgoingResource : Identifiable<long>
5959
{
6060
[Attr]
6161
public bool Attribute01 { get; set; }

docs/usage/errors.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ This handler is also the place to choose the log level and message, based on the
3434
```c#
3535
public class ProductOutOfStockException : Exception
3636
{
37-
public int ProductId { get; }
37+
public long ProductId { get; }
3838

39-
public ProductOutOfStockException(int productId)
39+
public ProductOutOfStockException(long productId)
4040
{
4141
ProductId = productId;
4242
}

docs/usage/extensibility/controllers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ You can even make your own mix of allowed routes by calling the alternate constr
126126
In some cases, resources may be an aggregation of entities or a view on top of the underlying entities. In these cases, there may not be a writable `IResourceService` implementation, so simply inject the implementation that is available.
127127

128128
```c#
129-
public class ReportsController : JsonApiController<Report, int>
129+
public class ReportsController : JsonApiController<Report, long>
130130
{
131131
public ReportsController(IJsonApiOptions options, IResourceGraph resourceGraph,
132-
ILoggerFactory loggerFactory, IGetAllService<Report, int> getAllService)
132+
ILoggerFactory loggerFactory, IGetAllService<Report, long> getAllService)
133133
: base(options, resourceGraph, loggerFactory, getAll: getAllService)
134134
{
135135
}

docs/usage/extensibility/repositories.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ If you only need minor changes you can override the methods defined in `EntityFr
55

66
```c#
77
// Program.cs
8-
builder.Services.AddScoped<IResourceRepository<Article, int>, ArticleRepository>();
9-
builder.Services.AddScoped<IResourceReadRepository<Article, int>, ArticleRepository>();
10-
builder.Services.AddScoped<IResourceWriteRepository<Article, int>, ArticleRepository>();
8+
builder.Services.AddScoped<IResourceRepository<Article, long>, ArticleRepository>();
9+
builder.Services.AddScoped<IResourceReadRepository<Article, long>, ArticleRepository>();
10+
builder.Services.AddScoped<IResourceWriteRepository<Article, long>, ArticleRepository>();
1111
```
1212

1313
In v4.0 we introduced an extension method that you can use to register a resource repository on all of its JsonApiDotNetCore interfaces.
@@ -26,7 +26,7 @@ A sample implementation that performs authorization might look like this.
2626
All of the methods in EntityFrameworkCoreRepository will use the `GetAll()` method to get the `DbSet<TResource>`, so this is a good method to apply filters such as user or tenant authorization.
2727

2828
```c#
29-
public class ArticleRepository : EntityFrameworkCoreRepository<Article, int>
29+
public class ArticleRepository : EntityFrameworkCoreRepository<Article, long>
3030
{
3131
private readonly IAuthenticationService _authenticationService;
3232

docs/usage/extensibility/resource-definitions.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ builder.Services.AddResourceDefinition<ArticleDefinition>();
1818
> [!NOTE]
1919
> Prior to the introduction of auto-discovery (in v3), you needed to register the resource definition on the container yourself:
2020
> ```c#
21-
> builder.Services.AddScoped<ResourceDefinition<Article, int>, ArticleDefinition>();
21+
> builder.Services.AddScoped<ResourceDefinition<Article, long>, ArticleDefinition>();
2222
> ```
2323
2424
## Customizing queries
@@ -41,7 +41,7 @@ For example, you may accept some sensitive data that should only be exposed to a
4141
> To exclude fields unconditionally, [attribute capabilities](~/usage/resources/attributes.md#capabilities) and [relationship capabilities](~/usage/resources/relationships.md#capabilities) can be used instead.
4242
4343
```c#
44-
public class UserDefinition : JsonApiResourceDefinition<User, int>
44+
public class UserDefinition : JsonApiResourceDefinition<User, long>
4545
{
4646
public UserDefinition(IResourceGraph resourceGraph)
4747
: base(resourceGraph)
@@ -100,7 +100,7 @@ Content-Type: application/vnd.api+json
100100
You can define the default sort order if no `sort` query string parameter is provided.
101101

102102
```c#
103-
public class AccountDefinition : JsonApiResourceDefinition<Account, int>
103+
public class AccountDefinition : JsonApiResourceDefinition<Account, long>
104104
{
105105
public AccountDefinition(IResourceGraph resourceGraph)
106106
: base(resourceGraph)
@@ -128,7 +128,7 @@ public class AccountDefinition : JsonApiResourceDefinition<Account, int>
128128
You may want to enforce pagination on large database tables.
129129

130130
```c#
131-
public class AccessLogDefinition : JsonApiResourceDefinition<AccessLog, int>
131+
public class AccessLogDefinition : JsonApiResourceDefinition<AccessLog, long>
132132
{
133133
public AccessLogDefinition(IResourceGraph resourceGraph)
134134
: base(resourceGraph)
@@ -159,7 +159,7 @@ public class AccessLogDefinition : JsonApiResourceDefinition<AccessLog, int>
159159
The next example filters out `Account` resources that are suspended.
160160

161161
```c#
162-
public class AccountDefinition : JsonApiResourceDefinition<Account, int>
162+
public class AccountDefinition : JsonApiResourceDefinition<Account, long>
163163
{
164164
public AccountDefinition(IResourceGraph resourceGraph)
165165
: base(resourceGraph)
@@ -188,7 +188,7 @@ public class AccountDefinition : JsonApiResourceDefinition<Account, int>
188188
In the example below, an error is returned when a user tries to include the manager of an employee.
189189

190190
```c#
191-
public class EmployeeDefinition : JsonApiResourceDefinition<Employee, int>
191+
public class EmployeeDefinition : JsonApiResourceDefinition<Employee, long>
192192
{
193193
public EmployeeDefinition(IResourceGraph resourceGraph)
194194
: base(resourceGraph)
@@ -224,7 +224,7 @@ If the key is present in a query string, the supplied LINQ expression will be ad
224224
But it only works on primary resource endpoints (for example: /articles, but not on /blogs/1/articles or /blogs?include=articles).
225225

226226
```c#
227-
public class ItemDefinition : JsonApiResourceDefinition<Item, int>
227+
public class ItemDefinition : JsonApiResourceDefinition<Item, long>
228228
{
229229
public ItemDefinition(IResourceGraph resourceGraph)
230230
: base(resourceGraph)

docs/usage/extensibility/services.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In simple cases, you can also just wrap the base implementation with your custom
1212
A simple example would be to send notifications when a resource gets created.
1313

1414
```c#
15-
public class TodoItemService : JsonApiResourceService<TodoItem, int>
15+
public class TodoItemService : JsonApiResourceService<TodoItem, long>
1616
{
1717
private readonly INotificationService _notificationService;
1818

@@ -51,14 +51,14 @@ If you'd like to use another ORM that does not provide what JsonApiResourceServi
5151
// Program.cs
5252
5353
// Add the service override for Product.
54-
builder.Services.AddScoped<IResourceService<Product, int>, ProductService>();
54+
builder.Services.AddScoped<IResourceService<Product, long>, ProductService>();
5555

5656
// Add your own Data Access Object.
5757
builder.Services.AddScoped<IProductDao, ProductDao>();
5858

5959
// ProductService.cs
6060
61-
public class ProductService : IResourceService<Product, int>
61+
public class ProductService : IResourceService<Product, long>
6262
{
6363
private readonly IProductDao _dao;
6464

@@ -114,14 +114,14 @@ IResourceCommandService <|-- IRemoveFromRelationshipService
114114
In order to take advantage of these interfaces you first need to register the service for each implemented interface.
115115

116116
```c#
117-
public class ArticleService : ICreateService<Article, int>, IDeleteService<Article, int>
117+
public class ArticleService : ICreateService<Article, long>, IDeleteService<Article, long>
118118
{
119119
// ...
120120
}
121121

122122
// Program.cs
123-
builder.Services.AddScoped<ICreateService<Article, int>, ArticleService>();
124-
builder.Services.AddScoped<IDeleteService<Article, int>, ArticleService>();
123+
builder.Services.AddScoped<ICreateService<Article, long>, ArticleService>();
124+
builder.Services.AddScoped<IDeleteService<Article, long>, ArticleService>();
125125
```
126126

127127
In v3.0 we introduced an extension method that you can use to register a resource service on all of its JsonApiDotNetCore interfaces.
@@ -140,7 +140,7 @@ Then on your model, pass in the set of endpoints to expose (the ones that you've
140140
```c#
141141
[Resource(GenerateControllerEndpoints =
142142
JsonApiEndpoints.Create | JsonApiEndpoints.Delete)]
143-
public class Article : Identifiable<int>
143+
public class Article : identifiable<long>
144144
{
145145
// ...
146146
}
@@ -149,11 +149,11 @@ public class Article : Identifiable<int>
149149
Alternatively, when using a hand-written controller, you should inherit from the JSON:API controller and pass the services into the named, optional base parameters:
150150

151151
```c#
152-
public class ArticlesController : JsonApiController<Article, int>
152+
public class ArticlesController : JsonApiController<Article, long>
153153
{
154154
public ArticlesController(IJsonApiOptions options, IResourceGraph resourceGraph,
155-
ILoggerFactory loggerFactory, ICreateService<Article, int> create,
156-
IDeleteService<Article, int> delete)
155+
ILoggerFactory loggerFactory, ICreateService<Article, long> create,
156+
IDeleteService<Article, long> delete)
157157
: base(options, resourceGraph, loggerFactory, create: create, delete: delete)
158158
{
159159
}

docs/usage/meta.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Resource-specific metadata can be added by implementing `IResourceDefinition<TRe
4747
```c#
4848
#nullable enable
4949

50-
public class PersonDefinition : JsonApiResourceDefinition<Person, int>
50+
public class PersonDefinition : JsonApiResourceDefinition<Person, long>
5151
{
5252
public PersonDefinition(IResourceGraph resourceGraph)
5353
: base(resourceGraph)

0 commit comments

Comments
 (0)