Skip to content

Commit e6ba54f

Browse files
committed
docs(readme): document custom context mapping
1 parent 94e5dee commit e6ba54f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,27 @@ By default, data retrieval is distributed across 3 layers:
236236

237237
Customization can be done at any of these layers. However, it is recommended that you make your customizations at the service or the repository layer when possible to keep the controllers free of unnecessary logic.
238238

239+
#### Not Using Entity Framework?
240+
241+
Out of the box, the library uses your `DbContext` to create a "ContextGraph" or map of all your models and their relationships. If, however, you have models that are not members of a `DbContext`, you can manually create this graph like so:
242+
243+
```csharp
244+
// Startup.cs
245+
public void ConfigureServices(IServiceCollection services)
246+
{
247+
// Add framework services.
248+
var mvcBuilder = services.AddMvc();
249+
250+
services.AddJsonApi(options => {
251+
options.Namespace = "api/v1";
252+
options.BuildContextGraph((builder) => {
253+
builder.AddResource<MyModel>("my-models");
254+
});
255+
}, mvcBuilder);
256+
// ...
257+
}
258+
```
259+
239260
#### Custom Resource Service Implementation
240261

241262
By default, this library uses Entity Framework. If you'd like to use another ORM that does not implement `IQueryable`, you can inject a custom service like so:

0 commit comments

Comments
 (0)