Skip to content

Commit 94e5dee

Browse files
committed
docs(readme): document custom data implementation
1 parent 2fd9eb3 commit 94e5dee

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,45 @@ services.AddJsonApi<AppDbContext>(
229229
### Defining Custom Data Access Methods
230230

231231
By default, data retrieval is distributed across 3 layers:
232+
232233
1. `JsonApiController`
233234
2. `EntityResourceService`
234235
3. `DefaultEntityRepository`
235236

236-
Customization can be done at any of these layers.
237+
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.
237238

238-
#### Custom Controller Methods
239+
#### Custom Resource Service Implementation
239240

240-
TODO
241+
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:
241242

242-
#### Custom Resource Service Implementation
243+
```csharp
244+
// Startup.cs
245+
public void ConfigureServices(IServiceCollection services)
246+
{
247+
services.AddScoped<IResourceService<MyModel>, MyModelService>();
248+
// ...
249+
}
250+
```
243251

244-
TODO
252+
```csharp
253+
// MyModelService.cs
254+
public class MyModelService : IResourceService<MyModel>
255+
{
256+
private readonly IMyModelDAL _dal;
257+
public MyModelService(IMyModelDAL dal)
258+
{
259+
_dal = dal;
260+
}
261+
public Task<IEnumerable<MyModel>> GetAsync()
262+
{
263+
return await _dal.GetModelAsync();
264+
}
265+
}
266+
```
245267

246268
#### Custom Entity Repository Implementation
247269

248-
You can implement custom methods for accessing the data by creating an implementation of
270+
If you want to use EF, but need additional data access logic (such as authorization), you can implement custom methods for accessing the data by creating an implementation of
249271
`IEntityRepository<TEntity, TId>`. If you only need minor changes you can override the
250272
methods defined in `DefaultEntityRepository<TEntity, TId>`. The repository should then be
251273
add to the service collection in `Startup.ConfigureServices` like so:

0 commit comments

Comments
 (0)