File tree 1 file changed +28
-1
lines changed
1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -175,7 +175,34 @@ methods defined in `DefaultEntityRepository<TEntity, TId>`. The repository shoul
175
175
add to the service collection in ` Startup.ConfigureServices ` like so:
176
176
177
177
``` 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
+ }
179
206
```
180
207
181
208
## Pagination
You can’t perform that action at this time.
0 commit comments