Skip to content

Commit 5d7d59f

Browse files
author
Bart Koelman
committed
Updated documentation to match with new style
1 parent ee4ec3f commit 5d7d59f

20 files changed

+386
-249
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ See [our documentation](https://www.jsonapi.net/) for detailed usage.
4242

4343
### Models
4444

45-
```csharp
45+
```c#
4646
public class Article : Identifiable
4747
{
4848
[Attr]
@@ -52,7 +52,7 @@ public class Article : Identifiable
5252

5353
### Controllers
5454

55-
```csharp
55+
```c#
5656
public class ArticlesController : JsonApiController<Article>
5757
{
5858
public ArticlesController(IJsonApiOptions options, IResourceService<Article> resourceService,
@@ -65,7 +65,7 @@ public class ArticlesController : JsonApiController<Article>
6565

6666
### Middleware
6767

68-
```csharp
68+
```c#
6969
public class Startup
7070
{
7171
public IServiceProvider ConfigureServices(IServiceCollection services)

docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ In addition, the example request/response pairs are generated by executing `curl
44

55
# Installation
66
Run the following commands once to setup your system:
7+
78
```
89
choco install docfx -y
910
```
11+
1012
```
1113
npm install -g httpserver
1214
```
1315

1416
# Running
1517
The next command regenerates the documentation website and opens it in your default browser:
18+
1619
```
1720
pwsh ./build-dev.ps1
1821
```

docs/getting-started/install.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
Click [here](https://www.nuget.org/packages/JsonApiDotnetCore/) for the latest NuGet version.
44

55
### CLI
6+
67
```
78
dotnet add package JsonApiDotnetCore
89
```
910

1011
### Visual Studio
12+
1113
```powershell
1214
Install-Package JsonApiDotnetCore
1315
```
1416

1517
### *.csproj
18+
1619
```xml
1720
<ItemGroup>
1821
<!-- Be sure to check NuGet for the latest version # -->

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ Nothing special here, just an ordinary `DbContext`
5353
public class AppDbContext : DbContext
5454
{
5555
public AppDbContext(DbContextOptions<AppDbContext> options)
56-
: base(options) { }
56+
: base(options)
57+
{
58+
}
5759
5860
public DbSet<Person> People { get; set; }
5961
}
@@ -67,12 +69,11 @@ where `TResource` is the model that inherits from `Identifiable<TId>`
6769
```c#
6870
public class PeopleController : JsonApiController<Person>
6971
{
70-
public PeopleController(
71-
IJsonApiOptions options,
72-
ILoggerFactory loggerFactory,
72+
public PeopleController(IJsonApiOptions options, ILoggerFactory loggerFactory,
7373
IResourceService<Person> resourceService)
74-
: base(options, loggerFactory, resourceService)
75-
{ }
74+
: base(options, loggerFactory, resourceService)
75+
{
76+
}
7677
}
7778
```
7879

@@ -123,6 +124,7 @@ public void Configure(IApplicationBuilder app, AppDbContext context)
123124
{
124125
Name = "John Doe"
125126
});
127+
126128
context.SaveChanges();
127129
}
128130

docs/usage/errors.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ You can create a custom error by throwing a `JsonApiException` (which accepts an
55
Please keep in mind that JSON:API requires Title to be a generic message, while Detail should contain information about the specific problem occurence.
66

77
From a controller method:
8+
89
```c#
910
return Conflict(new Error(HttpStatusCode.Conflict)
1011
{
@@ -14,6 +15,7 @@ return Conflict(new Error(HttpStatusCode.Conflict)
1415
```
1516

1617
From other code:
18+
1719
```c#
1820
throw new JsonApiException(new Error(HttpStatusCode.Conflict)
1921
{

docs/usage/extensibility/controllers.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ You need to create controllers that inherit from `JsonApiController<TResource>`
55
```c#
66
public class ArticlesController : JsonApiController<Article>
77
{
8-
public ArticlesController(
9-
IJsonApiOptions options,
10-
ILoggerFactory loggerFactory,
8+
public ArticlesController(IJsonApiOptions options, ILoggerFactory loggerFactory,
119
IResourceService<Article> resourceService)
1210
: base(options, loggerFactory, resourceService)
13-
{ }
11+
{
12+
}
1413
}
1514
```
1615

@@ -22,13 +21,12 @@ If your model is using a type other than `int` for the primary key, you must exp
2221
public class ArticlesController : JsonApiController<Article, Guid>
2322
//---------------------------------------------------------- ^^^^
2423
{
25-
public ArticlesController(
26-
IJsonApiOptions options,
27-
ILoggerFactory loggerFactory,
24+
public ArticlesController(IJsonApiOptions options, ILoggerFactory loggerFactory,
2825
IResourceService<Article, Guid> resourceService)
2926
//----------------------- ^^^^
3027
: base(options, loggerFactory, resourceService)
31-
{ }
28+
{
29+
}
3230
}
3331
```
3432

@@ -43,12 +41,11 @@ This approach is ok, but introduces some boilerplate that can easily be avoided.
4341
```c#
4442
public class ArticlesController : BaseJsonApiController<Article>
4543
{
46-
public ArticlesController(
47-
IJsonApiOptions options,
48-
ILoggerFactory loggerFactory,
44+
public ArticlesController(IJsonApiOptions options, ILoggerFactory loggerFactory,
4945
IResourceService<Article> resourceService)
5046
: base(options, loggerFactory, resourceService)
51-
{ }
47+
{
48+
}
5249

5350
[HttpGet]
5451
public override async Task<IActionResult> GetAsync(CancellationToken cancellationToken)
@@ -80,12 +77,11 @@ An attempt to use one of the blacklisted methods will result in a HTTP 405 Metho
8077
[HttpReadOnly]
8178
public class ArticlesController : BaseJsonApiController<Article>
8279
{
83-
public ArticlesController(
84-
IJsonApiOptions options,
85-
ILoggerFactory loggerFactory,
80+
public ArticlesController(IJsonApiOptions options, ILoggerFactory loggerFactory,
8681
IResourceService<Article> resourceService)
8782
: base(options, loggerFactory, resourceService)
88-
{ }
83+
{
84+
}
8985
}
9086
```
9187

@@ -100,12 +96,11 @@ For more information about resource injection, see the next section titled Resou
10096
```c#
10197
public class ReportsController : BaseJsonApiController<Report>
10298
{
103-
public ReportsController(
104-
IJsonApiOptions options,
105-
ILoggerFactory loggerFactory,
99+
public ReportsController(IJsonApiOptions options, ILoggerFactory loggerFactory,
106100
IResourceService<Report> resourceService)
107101
: base(options, loggerFactory, resourceService)
108-
{ }
102+
{
103+
}
109104

110105
[HttpGet]
111106
public override async Task<IActionResult> GetAsync(CancellationToken cancellationToken)

docs/usage/extensibility/middleware.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ It is possible to replace JsonApiDotNetCore middleware components by configuring
55
## Configuring the IoC container
66

77
The following example replaces the internal exception filter with a custom implementation.
8+
89
```c#
910
/// In Startup.ConfigureServices
10-
services.AddService<IAsyncJsonApiExceptionFilter, CustomAsyncExceptionFilter>()
11+
services.AddService<IAsyncJsonApiExceptionFilter, CustomAsyncExceptionFilter>();
1112
```
1213

1314
## Configuring `MvcOptions`
1415

1516
The following example replaces all internal filters with a custom filter.
17+
1618
```c#
1719
public class Startup
1820
{
@@ -22,7 +24,7 @@ public class Startup
2224
{
2325
services.AddSingleton<CustomAsyncQueryStringActionFilter>();
2426

25-
var builder = services.AddMvcCore();
27+
IMvcCoreBuilder builder = services.AddMvcCore();
2628
services.AddJsonApi<AppDbContext>(mvcBuilder: builder);
2729

2830
// Ensure this call is placed after the AddJsonApi call.
@@ -35,8 +37,8 @@ public class Startup
3537
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
3638
{
3739
// Ensure this call is placed before the UseEndpoints call.
38-
_postConfigureMvcOptions = mvcOptions =>
39-
{
40+
_postConfigureMvcOptions = mvcOptions =>
41+
{
4042
mvcOptions.Filters.Clear();
4143
mvcOptions.Filters.Insert(0,
4244
app.ApplicationServices.GetService<CustomAsyncQueryStringActionFilter>());

docs/usage/extensibility/repositories.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ public class ArticleRepository : EntityFrameworkCoreRepository<Article>
3636
{
3737
private readonly IAuthenticationService _authenticationService;
3838

39-
public ArticleRepository(
40-
IAuthenticationService authenticationService,
41-
ITargetedFields targetedFields,
42-
IDbContextResolver contextResolver,
43-
IResourceGraph resourceGraph,
44-
IGenericServiceFactory genericServiceFactory,
39+
public ArticleRepository(IAuthenticationService authenticationService,
40+
ITargetedFields targetedFields, IDbContextResolver contextResolver,
41+
IResourceGraph resourceGraph, IGenericServiceFactory genericServiceFactory,
4542
IResourceFactory resourceFactory,
4643
IEnumerable<IQueryConstraintProvider> constraintProviders,
4744
ILoggerFactory loggerFactory)
@@ -68,13 +65,15 @@ This example shows a single `DbContextARepository` for all entities that are mem
6865
public class DbContextARepository<TResource> : EntityFrameworkCoreRepository<TResource>
6966
where TResource : class, IIdentifiable<int>
7067
{
71-
public DbContextARepository(ITargetedFields targetedFields, DbContextResolver<DbContextA> contextResolver,
72-
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68+
public DbContextARepository(ITargetedFields targetedFields,
69+
DbContextResolver<DbContextA> contextResolver,
70+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7371
IResourceGraph resourceGraph, IGenericServiceFactory genericServiceFactory,
74-
IResourceFactory resourceFactory, IEnumerable<IQueryConstraintProvider> constraintProviders,
72+
IResourceFactory resourceFactory,
73+
IEnumerable<IQueryConstraintProvider> constraintProviders,
7574
ILoggerFactory loggerFactory)
76-
: base(targetedFields, contextResolver, resourceGraph, genericServiceFactory, resourceFactory,
77-
constraintProviders, loggerFactory)
75+
: base(targetedFields, contextResolver, resourceGraph, genericServiceFactory,
76+
resourceFactory, constraintProviders, loggerFactory)
7877
{
7978
}
8079
}
@@ -91,5 +90,5 @@ services.AddDbContext<DbContextB>(options => options.UseSqlite("Data Source=B.db
9190
services.AddScoped<IResourceRepository<ResourceA>, DbContextARepository<ResourceA>>();
9291
services.AddScoped<IResourceRepository<ResourceB>, DbContextBRepository<ResourceB>>();
9392

94-
services.AddJsonApi(dbContextTypes: new[] {typeof(DbContextA), typeof(DbContextB)});
93+
services.AddJsonApi(dbContextTypes: new[] { typeof(DbContextA), typeof(DbContextB) });
9594
```

docs/usage/extensibility/services.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,19 @@ public class TodoItemService : JsonApiResourceService<TodoItem>
1515
{
1616
private readonly INotificationService _notificationService;
1717

18-
public TodoItemService(
19-
IResourceRepositoryAccessor repositoryAccessor,
20-
IQueryLayerComposer queryLayerComposer,
21-
IPaginationContext paginationContext,
22-
IJsonApiOptions options,
23-
ILoggerFactory loggerFactory,
24-
IJsonApiRequest request,
18+
public TodoItemService(IResourceRepositoryAccessor repositoryAccessor,
19+
IQueryLayerComposer queryLayerComposer, IPaginationContext paginationContext,
20+
IJsonApiOptions options, ILoggerFactory loggerFactory, IJsonApiRequest request,
2521
IResourceChangeTracker<TodoItem> resourceChangeTracker,
2622
IResourceHookExecutorFacade hookExecutor)
27-
: base(repositoryAccessor, queryLayerComposer, paginationContext, options, loggerFactory,
28-
request, resourceChangeTracker, hookExecutor)
23+
: base(repositoryAccessor, queryLayerComposer, paginationContext, options,
24+
loggerFactory, request, resourceChangeTracker, hookExecutor)
2925
{
3026
_notificationService = notificationService;
3127
}
3228

33-
public override async Task<TodoItem> CreateAsync(TodoItem resource, CancellationToken cancellationToken)
29+
public override async Task<TodoItem> CreateAsync(TodoItem resource,
30+
CancellationToken cancellationToken)
3431
{
3532
// Call the base implementation
3633
var newResource = await base.CreateAsync(resource, cancellationToken);
@@ -69,7 +66,8 @@ public class ProductService : IResourceService<Product>
6966
_dao = dao;
7067
}
7168

72-
public async Task<IReadOnlyCollection<Product>> GetAsync(CancellationToken cancellationToken)
69+
public async Task<IReadOnlyCollection<Product>> GetAsync(
70+
CancellationToken cancellationToken)
7371
{
7472
return await _dao.GetProductsAsync(cancellationToken);
7573
}
@@ -152,22 +150,22 @@ Then in the controller, you should inherit from the base controller and pass the
152150
```c#
153151
public class ArticlesController : BaseJsonApiController<Article>
154152
{
155-
public ArticlesController(
156-
IJsonApiOptions options,
157-
ILoggerFactory loggerFactory,
158-
ICreateService<Article, int> create,
159-
IDeleteService<Article, int> delete)
153+
public ArticlesController(IJsonApiOptions options, ILoggerFactory loggerFactory,
154+
ICreateService<Article, int> create, IDeleteService<Article, int> delete)
160155
: base(options, loggerFactory, create: create, delete: delete)
161-
{ }
156+
{
157+
}
162158

163159
[HttpPost]
164-
public override async Task<IActionResult> PostAsync([FromBody] Article resource, CancellationToken cancellationToken)
160+
public override async Task<IActionResult> PostAsync([FromBody] Article resource,
161+
CancellationToken cancellationToken)
165162
{
166163
return await base.PostAsync(resource, cancellationToken);
167164
}
168165

169166
[HttpDelete("{id}")]
170-
public override async Task<IActionResult>DeleteAsync(int id, CancellationToken cancellationToken)
167+
public override async Task<IActionResult>DeleteAsync(int id,
168+
CancellationToken cancellationToken)
171169
{
172170
return await base.DeleteAsync(id, cancellationToken);
173171
}

docs/usage/meta.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public sealed class CopyrightResponseMeta : IResponseMeta
1818
return new Dictionary<string, object>
1919
{
2020
["copyright"] = "Copyright (C) 2002 Umbrella Corporation.",
21-
["authors"] = new[] {"Alice", "Red Queen"}
21+
["authors"] = new[] { "Alice", "Red Queen" }
2222
};
2323
}
2424
}
@@ -44,7 +44,8 @@ Resource-specific metadata can be added by implementing `IResourceDefinition<TRe
4444
```c#
4545
public class PersonDefinition : JsonApiResourceDefinition<Person>
4646
{
47-
public PersonDefinition(IResourceGraph resourceGraph) : base(resourceGraph)
47+
public PersonDefinition(IResourceGraph resourceGraph)
48+
: base(resourceGraph)
4849
{
4950
}
5051

@@ -54,7 +55,8 @@ public class PersonDefinition : JsonApiResourceDefinition<Person>
5455
{
5556
return new Dictionary<string, object>
5657
{
57-
["notice"] = "Check our intranet at http://www.example.com/employees/" + person.StringId + " for personal details."
58+
["notice"] = "Check our intranet at http://www.example.com/employees/" +
59+
person.StringId + " for personal details."
5860
};
5961
}
6062

docs/usage/options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ options.SerializerSettings.Formatting = Formatting.Indented;
9090
```
9191

9292
The default naming convention (as used in the routes and resource/attribute/relationship names) is also determined here, and can be changed (default is camel-case):
93+
9394
```c#
9495
options.SerializerSettings.ContractResolver = new DefaultContractResolver
9596
{

0 commit comments

Comments
 (0)