Skip to content

Feat/#293: Naming Conventions, Improvements to AutoDiscovery, and ResourceDefinition #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 3, 2018
8 changes: 7 additions & 1 deletion Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ $revision = "{0:D4}" -f [convert]::ToInt32($revision, 10)

dotnet restore

dotnet build ./src/Examples/GettingStarted/GettingStarted.csproj
CheckLastExitCode

dotnet test ./test/UnitTests/UnitTests.csproj
CheckLastExitCode

Expand All @@ -38,7 +41,10 @@ CheckLastExitCode
dotnet test ./test/ResourceEntitySeparationExampleTests/ResourceEntitySeparationExampleTests.csproj
CheckLastExitCode

dotnet build ./src/JsonApiDotNetCore -c Release
dotnet test ./test/DiscoveryTests/DiscoveryTests.csproj
CheckLastExitCode

dotnet build ./src/JsonApiDotNetCore/JsonApiDotNetCore.csproj -c Release
CheckLastExitCode

Write-Output "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG"
Expand Down
32 changes: 31 additions & 1 deletion JsonApiDotnetCore.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down Expand Up @@ -45,6 +45,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResourceEntitySeparationExa
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResourceEntitySeparationExampleTests", "test\ResourceEntitySeparationExampleTests\ResourceEntitySeparationExampleTests.csproj", "{6DFA30D7-1679-4333-9779-6FB678E48EF5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GettingStarted", "src\Examples\GettingStarted\GettingStarted.csproj", "{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscoveryTests", "test\DiscoveryTests\DiscoveryTests.csproj", "{09C0C8D8-B721-4955-8889-55CB149C3B5C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -187,6 +191,30 @@ Global
{6DFA30D7-1679-4333-9779-6FB678E48EF5}.Release|x64.Build.0 = Release|Any CPU
{6DFA30D7-1679-4333-9779-6FB678E48EF5}.Release|x86.ActiveCfg = Release|Any CPU
{6DFA30D7-1679-4333-9779-6FB678E48EF5}.Release|x86.Build.0 = Release|Any CPU
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Debug|x64.ActiveCfg = Debug|Any CPU
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Debug|x64.Build.0 = Debug|Any CPU
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Debug|x86.ActiveCfg = Debug|Any CPU
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Debug|x86.Build.0 = Debug|Any CPU
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Release|Any CPU.Build.0 = Release|Any CPU
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Release|x64.ActiveCfg = Release|Any CPU
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Release|x64.Build.0 = Release|Any CPU
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Release|x86.ActiveCfg = Release|Any CPU
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71}.Release|x86.Build.0 = Release|Any CPU
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|x64.ActiveCfg = Debug|Any CPU
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|x64.Build.0 = Debug|Any CPU
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|x86.ActiveCfg = Debug|Any CPU
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Debug|x86.Build.0 = Debug|Any CPU
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|Any CPU.Build.0 = Release|Any CPU
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x64.ActiveCfg = Release|Any CPU
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x64.Build.0 = Release|Any CPU
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x86.ActiveCfg = Release|Any CPU
{09C0C8D8-B721-4955-8889-55CB149C3B5C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -205,6 +233,8 @@ Global
{9CD2C116-D133-4FE4-97DA-A9FEAFF045F1} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
{F4097194-9415-418A-AB4E-315C5D5466AF} = {026FBC6C-AF76-4568-9B87-EC73457899FD}
{6DFA30D7-1679-4333-9779-6FB678E48EF5} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
{9B2A5AD7-0BF4-472E-A1B4-8BB623FDEB71} = {026FBC6C-AF76-4568-9B87-EC73457899FD}
{09C0C8D8-B721-4955-8889-55CB149C3B5C} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A2421882-8F0A-4905-928F-B550B192F9A4}
Expand Down
1 change: 1 addition & 0 deletions src/Examples/GettingStarted/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.db
15 changes: 15 additions & 0 deletions src/Examples/GettingStarted/Controllers/ArticlesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using GettingStarted.Models;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;

namespace GettingStarted
{
public class ArticlesController : JsonApiController<Article>
{
public ArticlesController(
IJsonApiContext jsonApiContext,
IResourceService<Article> resourceService)
: base(jsonApiContext, resourceService)
{ }
}
}
15 changes: 15 additions & 0 deletions src/Examples/GettingStarted/Controllers/PeopleController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using GettingStarted.Models;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;

namespace GettingStarted
{
public class PeopleController : JsonApiController<Person>
{
public PeopleController(
IJsonApiContext jsonApiContext,
IResourceService<Person> resourceService)
: base(jsonApiContext, resourceService)
{ }
}
}
17 changes: 17 additions & 0 deletions src/Examples/GettingStarted/Data/SampleDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using GettingStarted.Models;
using GettingStarted.ResourceDefinitionExample;
using Microsoft.EntityFrameworkCore;

namespace GettingStarted
{
public class SampleDbContext : DbContext
{
public SampleDbContext(DbContextOptions<SampleDbContext> options)
: base(options)
{ }

public DbSet<Article> Articles { get; set; }
public DbSet<Person> People { get; set; }
public DbSet<Model> Models { get; set; }
}
}
21 changes: 21 additions & 0 deletions src/Examples/GettingStarted/GettingStarted.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../../JsonApiDotNetCore/JsonApiDotNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.0" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions src/Examples/GettingStarted/Models/Article.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using JsonApiDotNetCore.Models;

namespace GettingStarted.Models
{
public class Article : Identifiable
{
[Attr]
public string Title { get; set; }

[HasOne]
public Person Author { get; set; }
public int AuthorId { get; set; }
}
}
14 changes: 14 additions & 0 deletions src/Examples/GettingStarted/Models/Person.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using JsonApiDotNetCore.Models;

namespace GettingStarted.Models
{
public class Person : Identifiable
{
[Attr]
public string Name { get; set; }

[HasMany]
public List<Article> Articles { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/Examples/GettingStarted/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace GettingStarted
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://localhost:5001")
.Build();
}
}
14 changes: 14 additions & 0 deletions src/Examples/GettingStarted/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Sample project

## Usage

`dotnet run` to run the project

You can verify the project is running by checking this endpoint:
`localhost:5001/api/sample-model`

For further documentation and implementation of a JsonApiDotnetCore Application see the documentation or GitHub page:

Repository: https://github.com/json-api-dotnet/JsonApiDotNetCore

Documentation: https://json-api-dotnet.github.io/
10 changes: 10 additions & 0 deletions src/Examples/GettingStarted/ResourceDefinitionExample/Model.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using JsonApiDotNetCore.Models;

namespace GettingStarted.ResourceDefinitionExample
{
public class Model : Identifiable
{
[Attr]
public string DontExpose { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using JsonApiDotNetCore.Models;

namespace GettingStarted.ResourceDefinitionExample
{
public class ModelDefinition : ResourceDefinition<Model>
{
// this allows POST / PATCH requests to set the value of a
// property, but we don't include this value in the response
// this might be used if the incoming value gets hashed or
// encrypted prior to being persisted and this value should
// never be sent back to the client
protected override List<AttrAttribute> OutputAttrs()
=> Remove(model => model.DontExpose);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using GettingStarted.Models;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;

namespace GettingStarted.ResourceDefinitionExample
{
public class ModelsController : JsonApiController<Model>
{
public ModelsController(
IJsonApiContext jsonApiContext,
IResourceService<Model> resourceService)
: base(jsonApiContext, resourceService)
{ }
}
}
38 changes: 38 additions & 0 deletions src/Examples/GettingStarted/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using JsonApiDotNetCore.Extensions;

namespace GettingStarted
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<SampleDbContext>(options =>
{
options.UseSqlite("Data Source=sample.db");
});

var mvcCoreBuilder = services.AddMvcCore();
services.AddJsonApi(
options => options.Namespace = "api",
mvcCoreBuilder,
discover => discover.AddCurrentAssembly());
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, SampleDbContext context)
{
context.Database.EnsureDeleted(); // indicies need to be reset
context.Database.EnsureCreated();

app.UseJsonApi();
}
}
}
5 changes: 2 additions & 3 deletions src/Examples/JsonApiDotNetCoreExample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ public virtual IServiceProvider ConfigureServices(IServiceCollection services)
options.IncludeTotalRecordCount = true;
},
mvcBuilder,
discovery => discovery.AddCurrentAssemblyServices());
discovery => discovery.AddCurrentAssembly());

var provider = services.BuildServiceProvider();
return provider;
return services.BuildServiceProvider();
}

public virtual void Configure(
Expand Down
8 changes: 4 additions & 4 deletions src/Examples/ReportsExample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public Startup(IHostingEnvironment env)
public virtual void ConfigureServices(IServiceCollection services)
{
var mvcBuilder = services.AddMvcCore();
services.AddJsonApi(
opt => opt.Namespace = "api",
mvcBuilder,
discovery => discovery.AddCurrentAssemblyServices());
services.AddJsonApi(
opt => opt.Namespace = "api",
mvcBuilder,
discovery => discovery.AddCurrentAssembly());
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
Expand Down
Loading