Skip to content

Commit 33d6771

Browse files
author
Bart Koelman
committed
Annotated example projects
1 parent 2f90361 commit 33d6771

Some content is hidden

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

46 files changed

+60
-140
lines changed

src/Examples/GettingStarted/Controllers/BooksController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using GettingStarted.Models;
42
using JsonApiDotNetCore.Configuration;
53
using JsonApiDotNetCore.Controllers;

src/Examples/GettingStarted/Controllers/PeopleController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using GettingStarted.Models;
42
using JsonApiDotNetCore.Configuration;
53
using JsonApiDotNetCore.Controllers;
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using GettingStarted.Models;
42
using JetBrains.Annotations;
53
using Microsoft.EntityFrameworkCore;
@@ -9,16 +7,11 @@ namespace GettingStarted.Data
97
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
108
public class SampleDbContext : DbContext
119
{
12-
public DbSet<Book> Books { get; set; }
10+
public DbSet<Book> Books => Set<Book>();
1311

1412
public SampleDbContext(DbContextOptions<SampleDbContext> options)
1513
: base(options)
1614
{
1715
}
18-
19-
protected override void OnModelCreating(ModelBuilder builder)
20-
{
21-
builder.Entity<Person>();
22-
}
2316
}
2417
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JetBrains.Annotations;
42
using JsonApiDotNetCore.Resources;
53
using JsonApiDotNetCore.Resources.Annotations;
@@ -10,12 +8,12 @@ namespace GettingStarted.Models
108
public sealed class Book : Identifiable<int>
119
{
1210
[Attr]
13-
public string Title { get; set; }
11+
public string Title { get; set; } = null!;
1412

1513
[Attr]
1614
public int PublishYear { get; set; }
1715

1816
[HasOne]
19-
public Person Author { get; set; }
17+
public Person Author { get; set; } = null!;
2018
}
2119
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using System.Collections.Generic;
42
using JetBrains.Annotations;
53
using JsonApiDotNetCore.Resources;
@@ -11,9 +9,9 @@ namespace GettingStarted.Models
119
public sealed class Person : Identifiable<int>
1210
{
1311
[Attr]
14-
public string Name { get; set; }
12+
public string Name { get; set; } = null!;
1513

1614
[HasMany]
17-
public ICollection<Book> Books { get; set; }
15+
public ICollection<Book> Books { get; set; } = new List<Book>();
1816
}
1917
}

src/Examples/GettingStarted/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using Microsoft.AspNetCore.Hosting;
42
using Microsoft.Extensions.Hosting;
53

src/Examples/GettingStarted/Startup.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using GettingStarted.Data;
42
using GettingStarted.Models;
53
using JetBrains.Annotations;

src/Examples/JsonApiDotNetCoreExample/Controllers/NonJsonApiController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using System.IO;
42
using System.Threading.Tasks;
53
using Microsoft.AspNetCore.Mvc;

src/Examples/JsonApiDotNetCoreExample/Controllers/OperationsController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JsonApiDotNetCore.AtomicOperations;
42
using JsonApiDotNetCore.Configuration;
53
using JsonApiDotNetCore.Controllers;

src/Examples/JsonApiDotNetCoreExample/Controllers/PeopleController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JsonApiDotNetCore.Configuration;
42
using JsonApiDotNetCore.Controllers;
53
using JsonApiDotNetCore.Services;

src/Examples/JsonApiDotNetCoreExample/Controllers/TagsController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JsonApiDotNetCore.Configuration;
42
using JsonApiDotNetCore.Controllers;
53
using JsonApiDotNetCore.Services;

src/Examples/JsonApiDotNetCoreExample/Controllers/TodoItemsController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JsonApiDotNetCore.Configuration;
42
using JsonApiDotNetCore.Controllers;
53
using JsonApiDotNetCore.Services;
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JetBrains.Annotations;
42
using JsonApiDotNetCoreExample.Models;
53
using Microsoft.EntityFrameworkCore;
@@ -11,7 +9,7 @@ namespace JsonApiDotNetCoreExample.Data
119
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
1210
public sealed class AppDbContext : DbContext
1311
{
14-
public DbSet<TodoItem> TodoItems { get; set; }
12+
public DbSet<TodoItem> TodoItems => Set<TodoItem>();
1513

1614
public AppDbContext(DbContextOptions<AppDbContext> options)
1715
: base(options)
@@ -23,16 +21,12 @@ protected override void OnModelCreating(ModelBuilder builder)
2321
// When deleting a person, un-assign him/her from existing todo items.
2422
builder.Entity<Person>()
2523
.HasMany(person => person.AssignedTodoItems)
26-
.WithOne(todoItem => todoItem.Assignee)
27-
.IsRequired(false)
28-
.OnDelete(DeleteBehavior.SetNull);
24+
.WithOne(todoItem => todoItem.Assignee!);
2925

3026
// When deleting a person, the todo items he/she owns are deleted too.
3127
builder.Entity<TodoItem>()
3228
.HasOne(todoItem => todoItem.Owner)
33-
.WithMany()
34-
.IsRequired()
35-
.OnDelete(DeleteBehavior.Cascade);
29+
.WithMany();
3630
}
3731
}
3832
}

src/Examples/JsonApiDotNetCoreExample/Definitions/TodoItemDefinition.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using System.ComponentModel;
42
using System.Threading;
53
using System.Threading.Tasks;
@@ -24,7 +22,7 @@ public TodoItemDefinition(IResourceGraph resourceGraph, ISystemClock systemClock
2422
_systemClock = systemClock;
2523
}
2624

27-
public override SortExpression OnApplySort(SortExpression existingSort)
25+
public override SortExpression OnApplySort(SortExpression? existingSort)
2826
{
2927
return existingSort ?? GetDefaultSortOrder();
3028
}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using System.Collections.Generic;
42
using JetBrains.Annotations;
53
using JsonApiDotNetCore.Resources;
@@ -11,12 +9,12 @@ namespace JsonApiDotNetCoreExample.Models
119
public sealed class Person : Identifiable<int>
1210
{
1311
[Attr]
14-
public string FirstName { get; set; }
12+
public string? FirstName { get; set; }
1513

1614
[Attr]
17-
public string LastName { get; set; }
15+
public string LastName { get; set; } = null!;
1816

1917
[HasMany]
20-
public ISet<TodoItem> AssignedTodoItems { get; set; }
18+
public ISet<TodoItem> AssignedTodoItems { get; set; } = new HashSet<TodoItem>();
2119
}
2220
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using System.Collections.Generic;
42
using System.ComponentModel.DataAnnotations;
53
using JetBrains.Annotations;
@@ -11,12 +9,11 @@ namespace JsonApiDotNetCoreExample.Models
119
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
1210
public sealed class Tag : Identifiable<int>
1311
{
14-
[Required]
15-
[MinLength(1)]
1612
[Attr]
17-
public string Name { get; set; }
13+
[MinLength(1)]
14+
public string Name { get; set; } = null!;
1815

1916
[HasMany]
20-
public ISet<TodoItem> TodoItems { get; set; }
17+
public ISet<TodoItem> TodoItems { get; set; } = new HashSet<TodoItem>();
2118
}
2219
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#nullable disable
2-
31
using System;
42
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
54
using JetBrains.Annotations;
65
using JsonApiDotNetCore.Resources;
76
using JsonApiDotNetCore.Resources.Annotations;
@@ -12,10 +11,11 @@ namespace JsonApiDotNetCoreExample.Models
1211
public sealed class TodoItem : Identifiable<int>
1312
{
1413
[Attr]
15-
public string Description { get; set; }
14+
public string Description { get; set; } = null!;
1615

1716
[Attr]
18-
public TodoItemPriority Priority { get; set; }
17+
[Required]
18+
public TodoItemPriority? Priority { get; set; }
1919

2020
[Attr(Capabilities = AttrCapabilities.AllowFilter | AttrCapabilities.AllowSort | AttrCapabilities.AllowView)]
2121
public DateTimeOffset CreatedAt { get; set; }
@@ -24,12 +24,12 @@ public sealed class TodoItem : Identifiable<int>
2424
public DateTimeOffset? LastModifiedAt { get; set; }
2525

2626
[HasOne]
27-
public Person Owner { get; set; }
27+
public Person Owner { get; set; } = null!;
2828

2929
[HasOne]
30-
public Person Assignee { get; set; }
30+
public Person? Assignee { get; set; }
3131

3232
[HasMany]
33-
public ISet<Tag> Tags { get; set; }
33+
public ISet<Tag> Tags { get; set; } = new HashSet<Tag>();
3434
}
3535
}

src/Examples/JsonApiDotNetCoreExample/Models/TodoItemPriority.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JetBrains.Annotations;
42

53
namespace JsonApiDotNetCoreExample.Models

src/Examples/JsonApiDotNetCoreExample/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using Microsoft.AspNetCore.Hosting;
42
using Microsoft.Extensions.Hosting;
53

src/Examples/JsonApiDotNetCoreExample/Startup.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using System;
42
using System.Text.Json.Serialization;
53
using JsonApiDotNetCore.Configuration;

src/Examples/MultiDbContextExample/Controllers/ResourceAsController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JsonApiDotNetCore.Configuration;
42
using JsonApiDotNetCore.Controllers;
53
using JsonApiDotNetCore.Services;

src/Examples/MultiDbContextExample/Controllers/ResourceBsController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JsonApiDotNetCore.Configuration;
42
using JsonApiDotNetCore.Controllers;
53
using JsonApiDotNetCore.Services;

src/Examples/MultiDbContextExample/Data/DbContextA.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JetBrains.Annotations;
42
using Microsoft.EntityFrameworkCore;
53
using MultiDbContextExample.Models;
@@ -9,7 +7,7 @@ namespace MultiDbContextExample.Data
97
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
108
public sealed class DbContextA : DbContext
119
{
12-
public DbSet<ResourceA> ResourceAs { get; set; }
10+
public DbSet<ResourceA> ResourceAs => Set<ResourceA>();
1311

1412
public DbContextA(DbContextOptions<DbContextA> options)
1513
: base(options)

src/Examples/MultiDbContextExample/Data/DbContextB.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JetBrains.Annotations;
42
using Microsoft.EntityFrameworkCore;
53
using MultiDbContextExample.Models;
@@ -9,7 +7,7 @@ namespace MultiDbContextExample.Data
97
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
108
public sealed class DbContextB : DbContext
119
{
12-
public DbSet<ResourceB> ResourceBs { get; set; }
10+
public DbSet<ResourceB> ResourceBs => Set<ResourceB>();
1311

1412
public DbContextB(DbContextOptions<DbContextB> options)
1513
: base(options)
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JetBrains.Annotations;
42
using JsonApiDotNetCore.Resources;
53
using JsonApiDotNetCore.Resources.Annotations;
@@ -10,6 +8,6 @@ namespace MultiDbContextExample.Models
108
public sealed class ResourceA : Identifiable<int>
119
{
1210
[Attr]
13-
public string NameA { get; set; }
11+
public string? NameA { get; set; }
1412
}
1513
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JetBrains.Annotations;
42
using JsonApiDotNetCore.Resources;
53
using JsonApiDotNetCore.Resources.Annotations;
@@ -10,6 +8,6 @@ namespace MultiDbContextExample.Models
108
public sealed class ResourceB : Identifiable<int>
119
{
1210
[Attr]
13-
public string NameB { get; set; }
11+
public string? NameB { get; set; }
1412
}
1513
}

src/Examples/MultiDbContextExample/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using Microsoft.AspNetCore.Hosting;
42
using Microsoft.Extensions.Hosting;
53

src/Examples/MultiDbContextExample/Properties/launchSettings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"$schema": "http://json.schemastore.org/launchsettings.json",
33
"iisSettings": {
44
"windowsAuthentication": false,
@@ -12,15 +12,15 @@
1212
"IIS Express": {
1313
"commandName": "IISExpress",
1414
"launchBrowser": false,
15-
"launchUrl": "/resourceBs",
15+
"launchUrl": "resourceBs",
1616
"environmentVariables": {
1717
"ASPNETCORE_ENVIRONMENT": "Development"
1818
}
1919
},
2020
"Kestrel": {
2121
"commandName": "Project",
2222
"launchBrowser": false,
23-
"launchUrl": "/resourceBs",
23+
"launchUrl": "resourceBs",
2424
"applicationUrl": "https://localhost:44350;http://localhost:14150",
2525
"environmentVariables": {
2626
"ASPNETCORE_ENVIRONMENT": "Development"

src/Examples/MultiDbContextExample/Repositories/DbContextARepository.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using System.Collections.Generic;
42
using JetBrains.Annotations;
53
using JsonApiDotNetCore.Configuration;

src/Examples/MultiDbContextExample/Repositories/DbContextBRepository.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using System.Collections.Generic;
42
using JetBrains.Annotations;
53
using JsonApiDotNetCore.Configuration;

src/Examples/MultiDbContextExample/Startup.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JetBrains.Annotations;
42
using JsonApiDotNetCore.Configuration;
53
using Microsoft.AspNetCore.Builder;

src/Examples/NoEntityFrameworkExample/Controllers/WorkItemsController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using JsonApiDotNetCore.Configuration;
42
using JsonApiDotNetCore.Controllers;
53
using JsonApiDotNetCore.Services;

0 commit comments

Comments
 (0)