Skip to content

Commit 4619e54

Browse files
committed
Separations for using IRepository pattern more easily
1 parent 220267c commit 4619e54

12 files changed

+113
-24
lines changed

MZBase.Domain/MZBase.Domain.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="MZSimpleDynamicLinq.Core" Version="1.0.3" />
16+
<PackageReference Include="MZSimpleDynamicLinq.Core" Version="1.0.4" />
1717
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
1818
</ItemGroup>
1919

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using MZBase.Domain;
3+
using MZBase.Infrastructure;
4+
using MZSimpleDynamicLinq.Core;
5+
using MZSimpleDynamicLinq.EFCoreExtensions;
6+
7+
namespace MZBase.EntityFrameworkCore
8+
{
9+
/// <summary>
10+
/// Provides an asynchronous repository implementation that is compatible with LinqDataRequest handling.
11+
/// </summary>
12+
/// <typeparam name="DBModelEntity">The type of the database model entity.</typeparam>
13+
/// <typeparam name="DomainModelEntity">The type of the domain model entity.</typeparam>
14+
/// <typeparam name="PrimaryKeyType">The type of the primary key.</typeparam>
15+
public class BaseLDRCompatibleRepositoryAsync<DomainModelEntity, DBModelEntity, PrimaryKeyType> : BaseRepositoryAsync<DomainModelEntity, DBModelEntity, PrimaryKeyType>, IBaseLDRCompatibleRepositoryAsync<DomainModelEntity, DBModelEntity, PrimaryKeyType>
16+
where DomainModelEntity : Model<PrimaryKeyType>
17+
where DBModelEntity : DomainModelEntity, IConvertibleDBModelEntity<DomainModelEntity>, new()
18+
where PrimaryKeyType : struct
19+
{
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="BaseLDRCompatibleRepositoryAsync{DBModelEntity, DomainModelEntity, PrimaryKeyType}"/> class.
22+
/// </summary>
23+
/// <param name="context">The database context.</param>
24+
public BaseLDRCompatibleRepositoryAsync(DbContext context) : base(context)
25+
{
26+
}
27+
28+
/// <summary>
29+
/// Gets all items asynchronously based on the specified LinqDataRequest.
30+
/// </summary>
31+
/// <param name="request">The LinqDataRequest containing the query parameters.</param>
32+
/// <returns>A task that represents the asynchronous operation. The task result contains the LinqDataResult of the domain model entities.</returns>
33+
public virtual async Task<LinqDataResult<DomainModelEntity>> AllItemsAsync(LinqDataRequest request)
34+
{
35+
return await _context.Set<DBModelEntity>().ToLinqDataResultAsync<DomainModelEntity>(request.Take, request.Skip, request.Sort, request.Filter);
36+
}
37+
}
38+
}

MZBase.EntityFrameworkCore/EFCoreStorageBusinessService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class EFCoreStorageBusinessService<DomainModel, DBModelEntity, P
1717
where DataContext : DbContext
1818
{
1919
protected readonly UnitOfWork _unitOfWork;
20-
protected readonly ILDRCompatibleRepositoryAsync<DomainModel, DBModelEntity, PrimaryKeyType> _baseRepo;
20+
protected readonly IBaseLDRCompatibleRepositoryAsync<DomainModel, DBModelEntity, PrimaryKeyType> _baseRepo;
2121

2222
public EFCoreStorageBusinessService(UnitOfWork unitOfWork,
2323
IDateTimeProviderService dateTimeProvider,

MZBase.EntityFrameworkCore/LDRComatibleRepositoryAsync.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ namespace MZBase.EntityFrameworkCore
1212
/// <typeparam name="DBModelEntity">The type of the database model entity.</typeparam>
1313
/// <typeparam name="DomainModelEntity">The type of the domain model entity.</typeparam>
1414
/// <typeparam name="PrimaryKeyType">The type of the primary key.</typeparam>
15-
public class LDRCompatibleRepositoryAsync<DomainModelEntity, DBModelEntity, PrimaryKeyType> : BaseRepositoryAsync<DomainModelEntity, DBModelEntity, PrimaryKeyType>, ILDRCompatibleRepositoryAsync<DomainModelEntity, DBModelEntity, PrimaryKeyType>
15+
public class LDRCompatibleRepositoryAsync<DomainModelEntity, DBModelEntity, PrimaryKeyType> : RepositoryAsync<DomainModelEntity, DBModelEntity, PrimaryKeyType>, ILDRCompatibleRepositoryAsync<DomainModelEntity, DBModelEntity, PrimaryKeyType>
1616
where DomainModelEntity : Model<PrimaryKeyType>
1717
where DBModelEntity : DomainModelEntity, IConvertibleDBModelEntity<DomainModelEntity>, new()
1818
where PrimaryKeyType : struct
1919
{
2020
/// <summary>
21-
/// Initializes a new instance of the <see cref="LDRCompatibleRepositoryAsync{DBModelEntity, DomainModelEntity, PrimaryKeyType}"/> class.
21+
/// Initializes a new instance of the <see cref="BaseLDRCompatibleRepositoryAsync{DBModelEntity, DomainModelEntity, PrimaryKeyType}"/> class.
2222
/// </summary>
2323
/// <param name="context">The database context.</param>
2424
public LDRCompatibleRepositoryAsync(DbContext context) : base(context)
@@ -34,5 +34,10 @@ public virtual async Task<LinqDataResult<DomainModelEntity>> AllItemsAsync(LinqD
3434
{
3535
return await _context.Set<DBModelEntity>().ToLinqDataResultAsync<DomainModelEntity>(request.Take, request.Skip, request.Sort, request.Filter);
3636
}
37+
38+
public virtual LinqDataResult<DomainModelEntity> AllItems(LinqDataRequest request)
39+
{
40+
return _context.Set<DBModelEntity>().ToLinqDataResult<DomainModelEntity>(request.Take, request.Skip, request.Sort, request.Filter);
41+
}
3742
}
3843
}

MZBase.EntityFrameworkCore/MZBase.EntityFrameworkCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Different repository implementations are included.</Description>
1616

1717
<ItemGroup>
1818
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
19-
<PackageReference Include="MZSimpleDynamicLinq.EFCoreExtensions" Version="1.0.2" />
19+
<PackageReference Include="MZSimpleDynamicLinq.EFCoreExtensions" Version="1.0.3" />
2020
</ItemGroup>
2121

2222
<ItemGroup>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using MZBase.Domain;
2+
using MZSimpleDynamicLinq.Core;
3+
using System.Threading.Tasks;
4+
5+
namespace MZBase.Infrastructure
6+
{
7+
/// <summary>
8+
/// Repository interface compatible with handling LinqDataRequest
9+
/// </summary>
10+
/// <typeparam name="ModelItem"></typeparam>
11+
/// <typeparam name="T"></typeparam>
12+
public interface IBaseLDRCompatibleRepositoryAsync<ModelItem, DBModelEntity, T> : IBaseRepositoryAsync<ModelItem, DBModelEntity, T>
13+
where ModelItem : Model<T>
14+
where DBModelEntity : ModelItem, IConvertibleDBModelEntity<ModelItem>, new()
15+
where T : struct
16+
{
17+
Task<LinqDataResult<ModelItem>> AllItemsAsync(LinqDataRequest request);
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using MZBase.Domain;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
5+
namespace MZBase.Infrastructure
6+
{
7+
/// <summary>
8+
/// Page-able, sortable and filterable repo interface
9+
/// </summary>
10+
/// <typeparam name="ModelItem"></typeparam>
11+
/// <typeparam name="T"></typeparam>
12+
public interface IBasePSFRepositoryAsync<ModelItem, DBModelEntity, T> : IBaseRepositoryAsync<ModelItem, DBModelEntity, T>
13+
where ModelItem : Model<T>
14+
where DBModelEntity : ModelItem, IConvertibleDBModelEntity<ModelItem>, new()
15+
where T : struct
16+
{
17+
Task<IReadOnlyList<ModelItem>> AllItemsAsync(int pageSize, int skip);
18+
Task<IReadOnlyList<ModelItem>> AllItemsAsync(int pageSize, int skip, string sortColumn, string sortDirection);
19+
Task<int> GetTotalCountAsync();
20+
}
21+
}

MZBase.Infrastructure/IDynamicTestableUnitOfWorkAsync.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace MZBase.Infrastructure
44
{
55
public interface IDynamicTestableUnitOfWorkAsync : IUnitOfWorkAsync
66
{
7-
ILDRCompatibleRepositoryAsync<DomainModel, DBModelEntity, PrimKey> GetRepo<DomainModel, DBModelEntity, PrimKey>()
7+
IBaseLDRCompatibleRepositoryAsync<DomainModel, DBModelEntity, PrimKey> GetRepo<DomainModel, DBModelEntity, PrimKey>()
88
where DomainModel : Model<PrimKey>
99
where DBModelEntity : DomainModel, IConvertibleDBModelEntity<DomainModel>, new()
1010
where PrimKey : struct;

MZBase.Infrastructure/ILDRComatibleRepositoryAsync.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ namespace MZBase.Infrastructure
99
/// </summary>
1010
/// <typeparam name="ModelItem"></typeparam>
1111
/// <typeparam name="T"></typeparam>
12-
public interface ILDRCompatibleRepositoryAsync<ModelItem, DBModelEntity, T> : IBaseRepositoryAsync<ModelItem, DBModelEntity, T>
12+
public interface ILDRCompatibleRepositoryAsync<ModelItem, DBModelEntity, T> : IRepositoryAsync<ModelItem, DBModelEntity, T>
1313
where ModelItem : Model<T>
1414
where DBModelEntity : ModelItem, IConvertibleDBModelEntity<ModelItem>, new()
1515
where T : struct
1616
{
1717
Task<LinqDataResult<ModelItem>> AllItemsAsync(LinqDataRequest request);
18+
LinqDataResult<ModelItem> AllItems(LinqDataRequest request);
1819
}
1920
}

MZBase.Infrastructure/IPSFRepositoryAsync.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ namespace MZBase.Infrastructure
99
/// </summary>
1010
/// <typeparam name="ModelItem"></typeparam>
1111
/// <typeparam name="T"></typeparam>
12-
public interface IPSFRepositoryAsync<ModelItem, DBModelEntity, T> : IBaseRepositoryAsync<ModelItem, DBModelEntity, T>
12+
public interface IPSFRepositoryAsync<ModelItem, DBModelEntity, T> : IRepositoryAsync<ModelItem, DBModelEntity, T>
1313
where ModelItem : Model<T>
1414
where DBModelEntity : ModelItem, IConvertibleDBModelEntity<ModelItem>, new()
1515
where T : struct
1616
{
1717
Task<IReadOnlyList<ModelItem>> AllItemsAsync(int pageSize, int skip);
1818
Task<IReadOnlyList<ModelItem>> AllItemsAsync(int pageSize, int skip, string sortColumn, string sortDirection);
1919
Task<int> GetTotalCountAsync();
20+
21+
IReadOnlyList<ModelItem> AllItems(int pageSize, int skip);
22+
IReadOnlyList<ModelItem> AllItems(int pageSize, int skip, string sortColumn, string sortDirection);
23+
int GetTotalCount();
24+
2025
}
2126
}

0 commit comments

Comments
 (0)