forked from json-api-dotnet/JsonApiDotNetCore
-
Notifications
You must be signed in to change notification settings - Fork 1
/
contextgraph.html
211 lines (190 loc) · 11.8 KB
/
contextgraph.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>JSONAPI .Net Core</title>
<link rel="stylesheet" href="https://json-api-dotnet.github.io/JsonApiDotNetCore/css/bootstrap.min.css">
<link rel="stylesheet" href="https://json-api-dotnet.github.io/JsonApiDotNetCore/css/font-awesome.min.css">
<link rel="stylesheet" href="https://json-api-dotnet.github.io/JsonApiDotNetCore/css/highlight.tomorrow-night.css">
<link rel="stylesheet" href="https://json-api-dotnet.github.io/JsonApiDotNetCore/css/main.css">
</head>
<body>
<header class="navbar navbar-default navbar-fixed-top">
<a class="navbar-brand" href="https://json-api-dotnet.github.io/JsonApiDotNetCore/">
JSONAPI .Net Core
<small class="hidden-xs hidden-sm">
killing boilerplate in dotnet web APIs
</small>
</a>
<a href="https://github.com/research-institute/json-api-dotnet-core">
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png">
</a>
</header>
<main class="container-fluid">
<div class="row">
<nav id="sidebar" class="col-sm-3 col-lg-2" role="navigation">
<p class="text-muted">
Getting Started
</p>
<ul class="nav nav-pills nav-stacked">
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/index.html">
About
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/installation.html">
Installation
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/usage.html">
Step by Step
</a>
</li>
</ul>
<p class="text-muted">
Usage
</p>
<ul class="nav nav-pills nav-stacked">
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/models.html">
Models
</a>
</li>
<li class="active">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/contextgraph.html">
Context Graph
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/meta.html">
Meta
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/options.html">
Global Options
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/errors.html">
Custom Errors
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/filtering.html">
Filtering
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/includingrelationships.html">
Including Relationships
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/pagination.html">
Pagination
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/routing.html">
Routing
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/sorting.html">
Sorting
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/sparsefieldsets.html">
Sparse Fieldsets
</a>
</li>
</ul>
<p class="text-muted">
Extensibility
</p>
<ul class="nav nav-pills nav-stacked">
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/layers.html">
The Layers
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/controllers.html">
Controllers
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/resourceservices.html">
Resource Services
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/entityrepositories.html">
Entity Repositories
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/middleware.html">
Middleware
</a>
</li>
<li class="">
<a href="https://json-api-dotnet.github.io/JsonApiDotNetCore/customqueryformat.html">
Custom Query Formats
</a>
</li>
</ul>
</nav>
<section class="col-sm-offset-3 col-lg-offset-2 col-sm-9 col-lg-10">
<h1 id="context-graph">Context Graph</h1>
<p>The <a href="https://github.com/Research-Institute/json-api-dotnet-core/blob/master/src/JsonApiDotNetCore/Internal/ContextGraph.cs">ContextGraph</a> is a map of all the json:api resources and their relationships that your API serves.
It is built at app startup and available as a singleton through Dependency Injection. </p>
<p>When you call <code>services.AddJsonApi<AppDbContext>()</code>, the graph is constructed from the context.</p>
<h3 id="defining-non-ef-resources">Defining Non-EF Resources</h3>
<p>If you have models that are not members of a <code>DbContext</code>,
you can manually create this graph like so:</p>
<pre><code class="language-csharp">// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
var mvcBuilder = services.AddMvc();
services.AddJsonApi(options => {
options.Namespace = "api/v1";
options.BuildContextGraph((builder) => {
builder.AddResource<MyModel>("my-models");
});
}, mvcBuilder);
// ...
}</code></pre>
<h3 id="changing-resource-names">Changing Resource Names</h3>
<p>If a DbContext is specified when adding the services, the context will be used to define the resources and their names. By default, these names will be hyphenated.</p>
<pre><code class="language-csharp">public class AppDbContext : DbContext {
// this will be translated into "my-models"
public DbSet<MyModel> MyModels { get; set; }
}</code></pre>
<p>However, you can specify a custom name like so:</p>
<pre><code class="language-csharp">public class AppDbContext : DbContext {
// this will be translated into "someModels"
[Resource("someModels")]
public DbSet<MyModel> MyModels { get; set; }
}</code></pre>
</section>
</div>
</main>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="//yandex.st/highlightjs/7.5/highlight.min.js"></script>
<script>
$(function() {
$("section>h1").wrap('<div class="page-header" />');
// Syntax highlighting
hljs.initHighlightingOnLoad();
});
</script>
</body>
</html>