-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGenericRepository.cs
More file actions
55 lines (40 loc) · 2.16 KB
/
Copy pathGenericRepository.cs
File metadata and controls
55 lines (40 loc) · 2.16 KB
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
using Anch.Core;
using Framework.Database;
using Anch.SecuritySystem.AccessDenied;
using Anch.SecuritySystem.Providers;
namespace Framework.Application.Repository.Generic;
public class GenericRepository<TDomainObject, TIdent>(
IAsyncDal<TDomainObject, TIdent> dal,
IAccessDeniedExceptionService accessDeniedExceptionService,
ISecurityProvider<TDomainObject> securityProvider)
: IGenericRepository<TDomainObject, TIdent>
where TDomainObject : class
{
public async Task SaveAsync(TDomainObject domainObject, CancellationToken cancellationToken)
{
await this.CheckAccess(domainObject, cancellationToken);
await dal.SaveAsync(domainObject, cancellationToken);
}
public async Task InsertAsync(TDomainObject domainObject, TIdent id, CancellationToken cancellationToken)
{
await this.CheckAccess(domainObject, cancellationToken);
await dal.InsertAsync(domainObject, id, cancellationToken);
}
public async Task RemoveAsync(TDomainObject domainObject, CancellationToken cancellationToken)
{
await this.CheckAccess(domainObject, cancellationToken);
await dal.RemoveAsync(domainObject, cancellationToken);
}
private ValueTask CheckAccess(TDomainObject domainObject, CancellationToken cancellationToken) =>
securityProvider.CheckAccessAsync(domainObject, accessDeniedExceptionService, cancellationToken);
public IQueryable<TDomainObject> GetQueryable() => dal.GetQueryable().Pipe(securityProvider.Inject);
public TDomainObject Load(TIdent id) => dal.Load(id);
public async Task<TDomainObject> LoadAsync(TIdent id, CancellationToken cancellationToken) =>
await dal.LoadAsync(id, cancellationToken);
/// <summary>
/// Re-read the state of the given instance from the underlying database.
/// </summary>
public async Task RefreshAsync(TDomainObject domainObject, CancellationToken cancellationToken) =>
await dal.RefreshAsync(domainObject, cancellationToken);
public async Task LockAsync(TDomainObject domainObject, LockRole lockRole, CancellationToken cancellationToken) => await dal.LockAsync(domainObject, lockRole, cancellationToken);
}