Skip to content

Commit 9e40590

Browse files
authored
Merge branch 'master' into new-docs
2 parents 97e7517 + 84f45a9 commit 9e40590

35 files changed

+940
-195
lines changed

Build.ps1

+10-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ $revision = "{0:D4}" -f [convert]::ToInt32($revision, 10)
2323

2424
dotnet restore
2525

26+
dotnet build ./src/Examples/GettingStarted/GettingStarted.csproj
27+
CheckLastExitCode
28+
2629
dotnet test ./test/UnitTests/UnitTests.csproj
2730
CheckLastExitCode
2831

@@ -35,7 +38,13 @@ CheckLastExitCode
3538
dotnet test ./test/OperationsExampleTests/OperationsExampleTests.csproj
3639
CheckLastExitCode
3740

38-
dotnet build .\src\JsonApiDotNetCore -c Release
41+
dotnet test ./test/ResourceEntitySeparationExampleTests/ResourceEntitySeparationExampleTests.csproj
42+
CheckLastExitCode
43+
44+
dotnet test ./test/DiscoveryTests/DiscoveryTests.csproj
45+
CheckLastExitCode
46+
47+
dotnet build ./src/JsonApiDotNetCore/JsonApiDotNetCore.csproj -c Release
3948
CheckLastExitCode
4049

4150
Write-Output "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG"

JsonApiDotnetCore.sln

+29-14
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResourceEntitySeparationExa
4545
EndProject
4646
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResourceEntitySeparationExampleTests", "test\ResourceEntitySeparationExampleTests\ResourceEntitySeparationExampleTests.csproj", "{6DFA30D7-1679-4333-9779-6FB678E48EF5}"
4747
EndProject
48-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GettingStarted", "src\Examples\GettingStarted\GettingStarted.csproj", "{DF9BFD82-D937-4907-B0B4-64670417115F}"
48+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GettingStarted", "src\Examples\GettingStarted\GettingStarted.csproj", "{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}"
49+
EndProject
50+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscoveryTests", "test\DiscoveryTests\DiscoveryTests.csproj", "{09C0C8D8-B721-4955-8889-55CB149C3B5C}"
4951
EndProject
5052
Global
5153
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -189,18 +191,30 @@ Global
189191
{6DFA30D7-1679-4333-9779-6FB678E48EF5}.Release|x64.Build.0 = Release|Any CPU
190192
{6DFA30D7-1679-4333-9779-6FB678E48EF5}.Release|x86.ActiveCfg = Release|Any CPU
191193
{6DFA30D7-1679-4333-9779-6FB678E48EF5}.Release|x86.Build.0 = Release|Any CPU
192-
{DF9BFD82-D937-4907-B0B4-64670417115F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
193-
{DF9BFD82-D937-4907-B0B4-64670417115F}.Debug|Any CPU.Build.0 = Debug|Any CPU
194-
{DF9BFD82-D937-4907-B0B4-64670417115F}.Debug|x64.ActiveCfg = Debug|Any CPU
195-
{DF9BFD82-D937-4907-B0B4-64670417115F}.Debug|x64.Build.0 = Debug|Any CPU
196-
{DF9BFD82-D937-4907-B0B4-64670417115F}.Debug|x86.ActiveCfg = Debug|Any CPU
197-
{DF9BFD82-D937-4907-B0B4-64670417115F}.Debug|x86.Build.0 = Debug|Any CPU
198-
{DF9BFD82-D937-4907-B0B4-64670417115F}.Release|Any CPU.ActiveCfg = Release|Any CPU
199-
{DF9BFD82-D937-4907-B0B4-64670417115F}.Release|Any CPU.Build.0 = Release|Any CPU
200-
{DF9BFD82-D937-4907-B0B4-64670417115F}.Release|x64.ActiveCfg = Release|Any CPU
201-
{DF9BFD82-D937-4907-B0B4-64670417115F}.Release|x64.Build.0 = Release|Any CPU
202-
{DF9BFD82-D937-4907-B0B4-64670417115F}.Release|x86.ActiveCfg = Release|Any CPU
203-
{DF9BFD82-D937-4907-B0B4-64670417115F}.Release|x86.Build.0 = Release|Any CPU
194+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
195+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Debug|Any CPU.Build.0 = Debug|Any CPU
196+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Debug|x64.ActiveCfg = Debug|Any CPU
197+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Debug|x64.Build.0 = Debug|Any CPU
198+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Debug|x86.ActiveCfg = Debug|Any CPU
199+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Debug|x86.Build.0 = Debug|Any CPU
200+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Release|Any CPU.ActiveCfg = Release|Any CPU
201+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Release|Any CPU.Build.0 = Release|Any CPU
202+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Release|x64.ActiveCfg = Release|Any CPU
203+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Release|x64.Build.0 = Release|Any CPU
204+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Release|x86.ActiveCfg = Release|Any CPU
205+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Release|x86.Build.0 = Release|Any CPU
206+
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
207+
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
208+
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|x64.ActiveCfg = Debug|Any CPU
209+
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|x64.Build.0 = Debug|Any CPU
210+
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|x86.ActiveCfg = Debug|Any CPU
211+
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|x86.Build.0 = Debug|Any CPU
212+
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
213+
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|Any CPU.Build.0 = Release|Any CPU
214+
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x64.ActiveCfg = Release|Any CPU
215+
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x64.Build.0 = Release|Any CPU
216+
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x86.ActiveCfg = Release|Any CPU
217+
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x86.Build.0 = Release|Any CPU
204218
EndGlobalSection
205219
GlobalSection(SolutionProperties) = preSolution
206220
HideSolutionNode = FALSE
@@ -219,7 +233,8 @@ Global
219233
{9CD2C116-D133-4FE4-97DA-A9FEAFF045F1} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
220234
{F4097194-9415-418A-AB4E-315C5D5466AF} = {026FBC6C-AF76-4568-9B87-EC73457899FD}
221235
{6DFA30D7-1679-4333-9779-6FB678E48EF5} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
222-
{DF9BFD82-D937-4907-B0B4-64670417115F} = {026FBC6C-AF76-4568-9B87-EC73457899FD}
236+
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71} = {026FBC6C-AF76-4568-9B87-EC73457899FD}
237+
{09C0C8D8-B721-4955-8889-55CB149C3B5C} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
223238
EndGlobalSection
224239
GlobalSection(ExtensibilityGlobals) = postSolution
225240
SolutionGuid = {A2421882-8F0A-4905-928F-B550B192F9A4}

build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ dotnet test ./test/UnitTests/UnitTests.csproj
99
dotnet test ./test/JsonApiDotNetCoreExampleTests/JsonApiDotNetCoreExampleTests.csproj
1010
dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj
1111
dotnet test ./test/OperationsExampleTests/OperationsExampleTests.csproj
12+
dotnet test ./test/ResourceEntitySeparationExampleTests/ResourceEntitySeparationExampleTests.csproj
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
using GettingStarted.Models;
22
using JsonApiDotNetCore.Controllers;
33
using JsonApiDotNetCore.Services;
4-
using Microsoft.Extensions.Logging;
54

65
namespace GettingStarted
76
{
87
public class ArticlesController : JsonApiController<Article>
98
{
109
public ArticlesController(
1110
IJsonApiContext jsonApiContext,
12-
IResourceService<Article> resourceService,
13-
ILoggerFactory loggerFactory)
14-
: base(jsonApiContext, resourceService, loggerFactory)
11+
IResourceService<Article> resourceService)
12+
: base(jsonApiContext, resourceService)
1513
{ }
1614
}
1715
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
using GettingStarted.Models;
22
using JsonApiDotNetCore.Controllers;
33
using JsonApiDotNetCore.Services;
4-
using Microsoft.Extensions.Logging;
54

65
namespace GettingStarted
76
{
87
public class PeopleController : JsonApiController<Person>
98
{
109
public PeopleController(
1110
IJsonApiContext jsonApiContext,
12-
IResourceService<Person> resourceService,
13-
ILoggerFactory loggerFactory)
14-
: base(jsonApiContext, resourceService, loggerFactory)
11+
IResourceService<Person> resourceService)
12+
: base(jsonApiContext, resourceService)
1513
{ }
1614
}
1715
}

src/Examples/GettingStarted/Data/SampleDbContext.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using GettingStarted.Models;
2+
using GettingStarted.ResourceDefinitionExample;
23
using Microsoft.EntityFrameworkCore;
34

45
namespace GettingStarted
@@ -11,5 +12,6 @@ public SampleDbContext(DbContextOptions<SampleDbContext> options)
1112

1213
public DbSet<Article> Articles { get; set; }
1314
public DbSet<Person> People { get; set; }
15+
public DbSet<Model> Models { get; set; }
1416
}
1517
}

src/Examples/GettingStarted/Models/Article.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ namespace GettingStarted.Models
44
{
55
public class Article : Identifiable
66
{
7-
[Attr("title")]
7+
[Attr]
88
public string Title { get; set; }
99

10-
[HasOne("author")]
10+
[HasOne]
1111
public Person Author { get; set; }
1212
public int AuthorId { get; set; }
1313
}

src/Examples/GettingStarted/Models/Person.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ namespace GettingStarted.Models
55
{
66
public class Person : Identifiable
77
{
8-
[Attr("name")]
8+
[Attr]
99
public string Name { get; set; }
1010

11-
[HasMany("articles")]
11+
[HasMany]
1212
public List<Article> Articles { get; set; }
1313
}
1414
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using JsonApiDotNetCore.Models;
2+
3+
namespace GettingStarted.ResourceDefinitionExample
4+
{
5+
public class Model : Identifiable
6+
{
7+
[Attr]
8+
public string DontExpose { get; set; }
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
using JsonApiDotNetCore.Models;
3+
4+
namespace GettingStarted.ResourceDefinitionExample
5+
{
6+
public class ModelDefinition : ResourceDefinition<Model>
7+
{
8+
// this allows POST / PATCH requests to set the value of a
9+
// property, but we don't include this value in the response
10+
// this might be used if the incoming value gets hashed or
11+
// encrypted prior to being persisted and this value should
12+
// never be sent back to the client
13+
protected override List<AttrAttribute> OutputAttrs()
14+
=> Remove(model => model.DontExpose);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using GettingStarted.Models;
2+
using JsonApiDotNetCore.Controllers;
3+
using JsonApiDotNetCore.Services;
4+
5+
namespace GettingStarted.ResourceDefinitionExample
6+
{
7+
public class ModelsController : JsonApiController<Model>
8+
{
9+
public ModelsController(
10+
IJsonApiContext jsonApiContext,
11+
IResourceService<Model> resourceService)
12+
: base(jsonApiContext, resourceService)
13+
{ }
14+
}
15+
}
+38-45
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,38 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Builder;
6-
using Microsoft.AspNetCore.Hosting;
7-
using Microsoft.AspNetCore.Http;
8-
using Microsoft.Extensions.DependencyInjection;
9-
using Microsoft.EntityFrameworkCore;
10-
using JsonApiDotNetCore.Extensions;
11-
12-
namespace GettingStarted
13-
{
14-
public class Startup
15-
{
16-
// This method gets called by the runtime. Use this method to add services to the container.
17-
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
18-
public void ConfigureServices(IServiceCollection services)
19-
{
20-
services.AddDbContext<SampleDbContext>(options =>
21-
{
22-
options.UseSqlite("Data Source=sample.db");
23-
});
24-
25-
services.AddJsonApi<SampleDbContext>(options =>
26-
{
27-
options.Namespace = "api";
28-
});
29-
}
30-
31-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
32-
public void Configure(IApplicationBuilder app, IHostingEnvironment env, SampleDbContext context)
33-
{
34-
if (env.IsDevelopment())
35-
{
36-
app.UseDeveloperExceptionPage();
37-
}
38-
39-
context.Database.EnsureDeleted(); // indicies need to be reset
40-
context.Database.EnsureCreated();
41-
42-
app.UseJsonApi();
43-
}
44-
}
45-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.AspNetCore.Http;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.EntityFrameworkCore;
10+
using JsonApiDotNetCore.Extensions;
11+
12+
namespace GettingStarted
13+
{
14+
public class Startup
15+
{
16+
public void ConfigureServices(IServiceCollection services)
17+
{
18+
services.AddDbContext<SampleDbContext>(options =>
19+
{
20+
options.UseSqlite("Data Source=sample.db");
21+
});
22+
23+
var mvcCoreBuilder = services.AddMvcCore();
24+
services.AddJsonApi(
25+
options => options.Namespace = "api",
26+
mvcCoreBuilder,
27+
discover => discover.AddCurrentAssembly());
28+
}
29+
30+
public void Configure(IApplicationBuilder app, IHostingEnvironment env, SampleDbContext context)
31+
{
32+
context.Database.EnsureDeleted(); // indicies need to be reset
33+
context.Database.EnsureCreated();
34+
35+
app.UseJsonApi();
36+
}
37+
}
38+
}

src/Examples/JsonApiDotNetCoreExample/Startup.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ public virtual IServiceProvider ConfigureServices(IServiceCollection services)
4141
options.IncludeTotalRecordCount = true;
4242
},
4343
mvcBuilder,
44-
discovery => discovery.AddCurrentAssemblyServices());
44+
discovery => discovery.AddCurrentAssembly());
4545

46-
var provider = services.BuildServiceProvider();
47-
return provider;
46+
return services.BuildServiceProvider();
4847
}
4948

5049
public virtual void Configure(

src/Examples/ReportsExample/Startup.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public Startup(IHostingEnvironment env)
2525
public virtual void ConfigureServices(IServiceCollection services)
2626
{
2727
var mvcBuilder = services.AddMvcCore();
28-
services.AddJsonApi(
29-
opt => opt.Namespace = "api",
30-
mvcBuilder,
31-
discovery => discovery.AddCurrentAssemblyServices());
28+
services.AddJsonApi(
29+
opt => opt.Namespace = "api",
30+
mvcBuilder,
31+
discovery => discovery.AddCurrentAssembly());
3232
}
3333

3434
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

0 commit comments

Comments
 (0)