Skip to content

Commit 8457b22

Browse files
committed
example: add "no entity framework" example
1 parent 4b859a3 commit 8457b22

24 files changed

+14523
-1
lines changed

JsonApiDotnetCore.sln

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.26228.4
@@ -18,10 +18,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1818
.gitignore = .gitignore
1919
EndProjectSection
2020
EndProject
21+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoEntityFrameworkExample", "src\NoEntityFrameworkExample\NoEntityFrameworkExample.csproj", "{570165EC-62B5-4684-A139-8D2A30DD4475}"
22+
EndProject
2123
Global
2224
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2325
Debug|Any CPU = Debug|Any CPU
2426
Release|Any CPU = Release|Any CPU
27+
Debug|x64 = Debug|x64
28+
Debug|x86 = Debug|x86
29+
Release|x64 = Release|x64
30+
Release|x86 = Release|x86
2531
EndGlobalSection
2632
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2733
{C0EC9E70-EB2E-436F-9D94-FA16FA774123}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -36,6 +42,18 @@ Global
3642
{0B959765-40D2-43B5-87EE-FE2FEF9DBED5}.Debug|Any CPU.Build.0 = Debug|Any CPU
3743
{0B959765-40D2-43B5-87EE-FE2FEF9DBED5}.Release|Any CPU.ActiveCfg = Release|Any CPU
3844
{0B959765-40D2-43B5-87EE-FE2FEF9DBED5}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{570165EC-62B5-4684-A139-8D2A30DD4475}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{570165EC-62B5-4684-A139-8D2A30DD4475}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{570165EC-62B5-4684-A139-8D2A30DD4475}.Debug|x64.ActiveCfg = Debug|x64
48+
{570165EC-62B5-4684-A139-8D2A30DD4475}.Debug|x64.Build.0 = Debug|x64
49+
{570165EC-62B5-4684-A139-8D2A30DD4475}.Debug|x86.ActiveCfg = Debug|x86
50+
{570165EC-62B5-4684-A139-8D2A30DD4475}.Debug|x86.Build.0 = Debug|x86
51+
{570165EC-62B5-4684-A139-8D2A30DD4475}.Release|Any CPU.ActiveCfg = Release|Any CPU
52+
{570165EC-62B5-4684-A139-8D2A30DD4475}.Release|Any CPU.Build.0 = Release|Any CPU
53+
{570165EC-62B5-4684-A139-8D2A30DD4475}.Release|x64.ActiveCfg = Release|x64
54+
{570165EC-62B5-4684-A139-8D2A30DD4475}.Release|x64.Build.0 = Release|x64
55+
{570165EC-62B5-4684-A139-8D2A30DD4475}.Release|x86.ActiveCfg = Release|x86
56+
{570165EC-62B5-4684-A139-8D2A30DD4475}.Release|x86.Build.0 = Release|x86
3957
EndGlobalSection
4058
GlobalSection(SolutionProperties) = preSolution
4159
HideSolutionNode = FALSE
@@ -44,5 +62,6 @@ Global
4462
{C0EC9E70-EB2E-436F-9D94-FA16FA774123} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
4563
{97EE048B-16C0-43F6-BDA9-4E762B2F579F} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
4664
{0B959765-40D2-43B5-87EE-FE2FEF9DBED5} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
65+
{570165EC-62B5-4684-A139-8D2A30DD4475} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
4766
EndGlobalSection
4867
EndGlobal
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using JsonApiDotNetCore.Controllers;
2+
using JsonApiDotNetCore.Services;
3+
using Microsoft.Extensions.Logging;
4+
using NoEntityFrameworkExample.Models;
5+
6+
namespace NoEntityFrameworkExample.Controllers
7+
{
8+
public class TodoItemsController : JsonApiController<TodoItem>
9+
{
10+
public TodoItemsController(
11+
IJsonApiContext jsonApiContext,
12+
IResourceService<TodoItem> resourceService,
13+
ILoggerFactory loggerFactory)
14+
: base(jsonApiContext, resourceService, loggerFactory)
15+
{ }
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using JsonApiDotNetCore.Models;
2+
3+
namespace NoEntityFrameworkExample.Models
4+
{
5+
public class TodoItem : Identifiable
6+
{
7+
[Attr("description")]
8+
public string Description { get; set; }
9+
}
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp1.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Folder Include="wwwroot\" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="../JsonApiDotNetCore/JsonApiDotNetCore.csproj" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
17+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
18+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Builder;
7+
using Microsoft.AspNetCore.Hosting;
8+
9+
namespace NoEntityFrameworkExample
10+
{
11+
public class Program
12+
{
13+
public static void Main(string[] args)
14+
{
15+
var host = new WebHostBuilder()
16+
.UseKestrel()
17+
.UseContentRoot(Directory.GetCurrentDirectory())
18+
.UseIISIntegration()
19+
.UseStartup<Startup>()
20+
.Build();
21+
22+
host.Run();
23+
}
24+
}
25+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using JsonApiDotNetCore.Models;
5+
using JsonApiDotNetCore.Services;
6+
using NoEntityFrameworkExample.Models;
7+
8+
namespace NoEntityFrameworkExample.Services
9+
{
10+
public class TodoItemService : IResourceService<TodoItem>
11+
{
12+
public Task<TodoItem> CreateAsync(TodoItem entity)
13+
{
14+
throw new NotImplementedException();
15+
}
16+
17+
public Task<bool> DeleteAsync(int id)
18+
{
19+
throw new NotImplementedException();
20+
}
21+
22+
public Task<IEnumerable<TodoItem>> GetAsync()
23+
{
24+
return Task.Run<IEnumerable<TodoItem>>(() => {
25+
return new List<TodoItem> {
26+
new TodoItem {
27+
Description = "description"
28+
}
29+
};
30+
});
31+
}
32+
33+
public Task<TodoItem> GetAsync(int id)
34+
{
35+
throw new NotImplementedException();
36+
}
37+
38+
public Task<object> GetRelationshipAsync(int id, string relationshipName)
39+
{
40+
throw new NotImplementedException();
41+
}
42+
43+
public Task<object> GetRelationshipsAsync(int id, string relationshipName)
44+
{
45+
throw new NotImplementedException();
46+
}
47+
48+
public Task<TodoItem> UpdateAsync(int id, TodoItem entity)
49+
{
50+
throw new NotImplementedException();
51+
}
52+
53+
public Task UpdateRelationshipsAsync(int id, string relationshipName, List<DocumentData> relationships)
54+
{
55+
throw new NotImplementedException();
56+
}
57+
}
58+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using JsonApiDotNetCore.Extensions;
2+
using JsonApiDotNetCore.Services;
3+
using Microsoft.AspNetCore.Builder;
4+
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.EntityFrameworkCore;
6+
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Logging;
9+
using NoEntityFrameworkExample.Models;
10+
using NoEntityFrameworkExample.Services;
11+
12+
namespace NoEntityFrameworkExample
13+
{
14+
public class Startup
15+
{
16+
public Startup(IHostingEnvironment env)
17+
{
18+
var builder = new ConfigurationBuilder()
19+
.SetBasePath(env.ContentRootPath)
20+
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
21+
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
22+
.AddEnvironmentVariables();
23+
Configuration = builder.Build();
24+
}
25+
26+
public IConfigurationRoot Configuration { get; }
27+
28+
// This method gets called by the runtime. Use this method to add services to the container.
29+
public void ConfigureServices(IServiceCollection services)
30+
{
31+
// Add framework services.
32+
var mvcBuilder = services.AddMvc();
33+
34+
services.AddJsonApi(options => {
35+
options.Namespace = "api/v1";
36+
options.BuildContextGraph((builder) => {
37+
builder.AddResource<TodoItem>("todo-items");
38+
});
39+
}, mvcBuilder);
40+
41+
services.AddScoped<IResourceService<TodoItem>, TodoItemService>();
42+
}
43+
44+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
45+
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
46+
{
47+
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
48+
loggerFactory.AddDebug();
49+
50+
app.UseMvc();
51+
}
52+
}
53+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"LogLevel": {
5+
"Default": "Debug",
6+
"System": "Information",
7+
"Microsoft": "Information"
8+
}
9+
}
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"LogLevel": {
5+
"Default": "Warning"
6+
}
7+
}
8+
}
Binary file not shown.

0 commit comments

Comments
 (0)