Skip to content

Commit f7bdf11

Browse files
committed
docs(readme): add data access override example
1 parent e95befd commit f7bdf11

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,34 @@ methods defined in `DefaultEntityRepository<TEntity, TId>`. The repository shoul
175175
add to the service collection in `Startup.ConfigureServices` like so:
176176

177177
```csharp
178-
services.AddScoped<IEntityRepository<MyEntity,Guid>, MyEntityRepository>();
178+
services.AddScoped<IEntityRepository<MyEntity,Guid>, MyAuthorizedEntityRepository>();
179+
```
180+
181+
A sample implementation might look like:
182+
183+
```chsarp
184+
public class MyAuthorizedEntityRepository : DefaultEntityRepository<MyEntity>
185+
{
186+
private readonly ILogger _logger;
187+
private readonly AppDbContext _context;
188+
private readonly IAuthenticationService _authenticationService;
189+
190+
public MyAuthorizedEntityRepository(AppDbContext context,
191+
ILoggerFactory loggerFactory,
192+
IJsonApiContext jsonApiContext,
193+
IAuthenticationService authenticationService)
194+
: base(context, loggerFactory, jsonApiContext)
195+
{
196+
_context = context;
197+
_logger = loggerFactory.CreateLogger<MyEntityRepository>();
198+
_authenticationService = authenticationService;
199+
}
200+
201+
public override IQueryable<MyEntity> Get()
202+
{
203+
return base.Get().Where(e => e.UserId == _authenticationService.UserId);
204+
}
205+
}
179206
```
180207

181208
## Pagination

0 commit comments

Comments
 (0)