Skip to content

Commit

Permalink
Merge pull request #7 from Nikoo-Asadnejad/develop
Browse files Browse the repository at this point in the history
refactor : return readonlyList in queryRepository
  • Loading branch information
Nikoo-Asadnejad authored Oct 22, 2023
2 parents 7da9dde + af104c2 commit ddbf592
Show file tree
Hide file tree
Showing 36 changed files with 434 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,30 @@
"System.Threading": "4.3.0"
}
},
"Microsoft.EntityFrameworkCore/7.0.0": {
"Microsoft.EntityFrameworkCore/7.0.10": {
"dependencies": {
"Microsoft.EntityFrameworkCore.Abstractions": "7.0.0",
"Microsoft.EntityFrameworkCore.Analyzers": "7.0.0",
"Microsoft.EntityFrameworkCore.Abstractions": "7.0.10",
"Microsoft.EntityFrameworkCore.Analyzers": "7.0.10",
"Microsoft.Extensions.Caching.Memory": "7.0.0",
"Microsoft.Extensions.DependencyInjection": "7.0.0",
"Microsoft.Extensions.Logging": "7.0.0"
},
"runtime": {
"lib/net6.0/Microsoft.EntityFrameworkCore.dll": {
"assemblyVersion": "7.0.0.0",
"fileVersion": "7.0.22.51807"
"assemblyVersion": "7.0.10.0",
"fileVersion": "7.0.1023.36204"
}
}
},
"Microsoft.EntityFrameworkCore.Abstractions/7.0.0": {
"Microsoft.EntityFrameworkCore.Abstractions/7.0.10": {
"runtime": {
"lib/net6.0/Microsoft.EntityFrameworkCore.Abstractions.dll": {
"assemblyVersion": "7.0.0.0",
"fileVersion": "7.0.22.51807"
"assemblyVersion": "7.0.10.0",
"fileVersion": "7.0.1023.36204"
}
}
},
"Microsoft.EntityFrameworkCore.Analyzers/7.0.0": {},
"Microsoft.EntityFrameworkCore.Analyzers/7.0.10": {},
"Microsoft.Extensions.Caching.Abstractions/7.0.0": {
"dependencies": {
"Microsoft.Extensions.Primitives": "7.0.0"
Expand Down Expand Up @@ -461,7 +461,7 @@
},
"Moq.EntityFrameworkCore/7.0.0.2": {
"dependencies": {
"Microsoft.EntityFrameworkCore": "7.0.0",
"Microsoft.EntityFrameworkCore": "7.0.10",
"Moq": "4.18.4"
},
"runtime": {
Expand Down Expand Up @@ -1293,8 +1293,8 @@
"xunit.runner.visualstudio/2.4.5": {},
"GenericRepository/1.0.0": {
"dependencies": {
"Microsoft.EntityFrameworkCore": "7.0.0",
"Microsoft.EntityFrameworkCore.Abstractions": "7.0.0",
"Microsoft.EntityFrameworkCore": "7.0.10",
"Microsoft.EntityFrameworkCore.Abstractions": "7.0.10",
"Scrutor": "4.2.0"
},
"runtime": {
Expand Down Expand Up @@ -1337,26 +1337,26 @@
"path": "microsoft.csharp/4.0.1",
"hashPath": "microsoft.csharp.4.0.1.nupkg.sha512"
},
"Microsoft.EntityFrameworkCore/7.0.0": {
"Microsoft.EntityFrameworkCore/7.0.10": {
"type": "package",
"serviceable": true,
"sha512": "sha512-9W+IfmAzMrp2ZpKZLhgTlWljSBM9Erldis1us61DAGi+L7Q6vilTbe1G2zDxtYO8F2H0I0Qnupdx5Cp4s2xoZw==",
"path": "microsoft.entityframeworkcore/7.0.0",
"hashPath": "microsoft.entityframeworkcore.7.0.0.nupkg.sha512"
"sha512": "sha512-24NbXJqJ/x8u88/agqeb1pLdAF9+9StDLA36+P/3g5xsJPOaB2GxXn7epR8dWpZTgHsNZ7cvBMxBgfFmF+xZlg==",
"path": "microsoft.entityframeworkcore/7.0.10",
"hashPath": "microsoft.entityframeworkcore.7.0.10.nupkg.sha512"
},
"Microsoft.EntityFrameworkCore.Abstractions/7.0.0": {
"Microsoft.EntityFrameworkCore.Abstractions/7.0.10": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Pfu3Zjj5+d2Gt27oE9dpGiF/VobBB+s5ogrfI9sBsXQE1SG49RqVz5+IyeNnzhyejFrPIQsPDRMchhcojy4Hbw==",
"path": "microsoft.entityframeworkcore.abstractions/7.0.0",
"hashPath": "microsoft.entityframeworkcore.abstractions.7.0.0.nupkg.sha512"
"sha512": "sha512-Z/lDWmGLiT9uNQrp6UXTKZxofSmAKQCiKOz98FDscTbfAGgBXE3DTTqRsPMc8HFIVVSNANSiFRz3JyLg07HN9Q==",
"path": "microsoft.entityframeworkcore.abstractions/7.0.10",
"hashPath": "microsoft.entityframeworkcore.abstractions.7.0.10.nupkg.sha512"
},
"Microsoft.EntityFrameworkCore.Analyzers/7.0.0": {
"Microsoft.EntityFrameworkCore.Analyzers/7.0.10": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Qkd2H+jLe37o5ku+LjT6qf7kAHY75Yfn2bBDQgqr13DTOLYpEy1Mt93KPFjaZvIu/srEcbfGGMRL7urKm5zN8Q==",
"path": "microsoft.entityframeworkcore.analyzers/7.0.0",
"hashPath": "microsoft.entityframeworkcore.analyzers.7.0.0.nupkg.sha512"
"sha512": "sha512-+8NVNpyJTzW6nNh/7RGfldf+mbeboVcn+X1tD8kMBCEJswuy3RqM/qecEEfOfTcWLliZExPMaHwOwtHO6RMpdA==",
"path": "microsoft.entityframeworkcore.analyzers/7.0.10",
"hashPath": "microsoft.entityframeworkcore.analyzers.7.0.10.nupkg.sha512"
},
"Microsoft.Extensions.Caching.Abstractions/7.0.0": {
"type": "package",
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified GenericRepository.Tests/bin/Debug/net7.0/GenericRepository.dll
Binary file not shown.
Binary file modified GenericRepository.Tests/bin/Debug/net7.0/GenericRepository.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fbaa12cf52dedb3aecaaf600ca4ab14ee0c07b5b
3dbd4bf0230f3a5df2440d4cbe8dfda86a0b65b5
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions GenericRepository/Abstractions/BaseRepository.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using GenericRepository.Abstractions.Interfaces.UnitOfWork;
using Microsoft.EntityFrameworkCore;

namespace GenericRepository.Abstractions;

public abstract class BaseRepository
{
private readonly IUnitOfwork _unitOfwork;

public BaseRepository(IUnitOfwork unitOfwork)
private readonly IUnitOfWork _unitOfWork;
protected BaseRepository(IUnitOfWork unitOfWork)
{
_unitOfwork = unitOfwork;
_unitOfWork = unitOfWork;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ namespace GenericRepository.Abstractions.Interfaces.GenericRepository.Command;

public partial interface IRepository<T> where T : BaseEntity
{
Task<IDbContextTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default);
Task RollbackTransactionAsync();
Task CommitTransactionAsync();

Task AddAsync(T model);
Task AddRangeAsync(IEnumerable<T> models);
Task UpdateAsync(T model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Task<T> GetSingleAsync(Expression<Func<T, bool>>? query,
/// <param name="distinct">isDistinct</param>
/// <param name="asTracking">On or Off tracking</param>
/// <returns></returns>
Task<List<TResult>> GetListAsync<TResult>(Expression<Func<T, bool>>? query,
Task<IReadOnlyList<TResult>> GetListAsync<TResult>(Expression<Func<T, bool>>? query,
Func<T, TResult> selector,
Func<T, object>? orderBy = default,
OrderType? orderType = OrderType.Asc,
Expand All @@ -38,7 +38,7 @@ Task<List<TResult>> GetListAsync<TResult>(Expression<Func<T, bool>>? query,
bool? distinct = null,
bool asTracking = false);

Task<List<T>> GetListAsync(Expression<Func<T, bool>>? query = default,
Task<IReadOnlyList<T>> GetListAsync(Expression<Func<T, bool>>? query = default,
Func<T, object>? orderBy = default,
OrderType? orderType = OrderType.Asc,
List<string>? includes = default,
Expand All @@ -47,7 +47,7 @@ Task<List<T>> GetListAsync(Expression<Func<T, bool>>? query = default,
bool? distinct = default,
bool asTracking = false);

Task<List<TResult>> GetAllAsync<TResult>(Func<T, TResult> selector,
Task<IReadOnlyList<TResult>> GetAllAsync<TResult>(Func<T, TResult> selector,
Func<T, object>? orderBy = default,
OrderType? orderType = OrderType.Asc,
List<string>? includes = default,
Expand All @@ -56,7 +56,7 @@ Task<List<TResult>> GetAllAsync<TResult>(Func<T, TResult> selector,
bool? distinct = false,
bool asTracking = false);

Task<List<T>> GetAllAsync(Func<T, object>? orderBy = default,
Task<IReadOnlyList<T>> GetAllAsync(Func<T, object>? orderBy = default,
OrderType? orderType = OrderType.Asc,
List<string>? includes = default,
int? skip = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ T GetSingle(Expression<Func<T, bool>>? query,
List<string>? includes = null,
bool asTracking = false);

List<TResult> GetList<TResult>(Expression<Func<T, bool>>? query,
IReadOnlyList<TResult> GetList<TResult>(Expression<Func<T, bool>>? query,
Func<T, TResult> selector,
Func<T, object>? orderBy = default,
OrderType? orderType = OrderType.Asc,
Expand All @@ -28,7 +28,7 @@ List<TResult> GetList<TResult>(Expression<Func<T, bool>>? query,
bool asTracking = false);


List<T> GetList(Expression<Func<T, bool>>? query = default,
IReadOnlyList<T> GetList(Expression<Func<T, bool>>? query = default,
Func<T, object>? orderBy = default,
OrderType? orderType = OrderType.Asc,
List<string>? includes = default,
Expand All @@ -37,7 +37,7 @@ List<T> GetList(Expression<Func<T, bool>>? query = default,
bool? distinct = false,
bool asTracking = false);

List<TResult> GetAll<TResult>(Func<T, TResult> selector,
IReadOnlyList<TResult> GetAll<TResult>(Func<T, TResult> selector,
Func<T, object>? orderBy = default,
OrderType? orderType = OrderType.Asc,
List<string>? includes = default,
Expand All @@ -46,7 +46,7 @@ List<TResult> GetAll<TResult>(Func<T, TResult> selector,
bool? distinct = null,
bool asTracking = false);

List<T> GetAll(Func<T, object>? orderBy = default,
IReadOnlyList<T> GetAll(Func<T, object>? orderBy = default,
OrderType? orderType = OrderType.Asc,
List<string>? includes = null,
int? skip = 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;

namespace GenericRepository.Abstractions.Interfaces.UnitOfWork;

public interface IUnitOfWork
{
Task<int> SaveAsync();
int Save();
Task DisposeAsync();
void Dispose();
Task<IDbContextTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default);
Task RollbackTransactionAsync();
Task CommitTransactionAsync();
}

This file was deleted.

3 changes: 2 additions & 1 deletion GenericRepository/Data/QueryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class QueryContext : DbContext
{
public QueryContext(DbContextOptions<QueryContext> options) : base(options)
{

}

}
1 change: 0 additions & 1 deletion GenericRepository/Entities/BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ public abstract class BaseEntity
public long CreateDate { get; private set; }
public long? UpdateDate { get; private set; }
public long? DeleteDate { get; private set; }

public bool IsDeleted { get; private set; } = false;

public BaseEntity Create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class GenericRepositoryConfigurator
public static void InjectServices(IServiceCollection services)
{
services.AddMemoryCache();
services.AddTransient<IUnitOfwork, UnitOfWork>();
services.AddTransient<IUnitOfWork, UnitOfWork>();
services.AddScoped<DbContext, CommandContext>();
services.AddScoped<DbContext, QueryContext>();
services.AddTransient(typeof(IRepository<>), typeof(Repository<>));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ public Repository(CommandContext context)
this._context = context;
_model = _context.Set<T>();
}

public async Task<IDbContextTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default)
{
IDbContextTransaction dbContextTransaction = await _context.Database.BeginTransactionAsync(cancellationToken);
return dbContextTransaction;
}
public async Task RollbackTransactionAsync()
=>await _context.Database.RollbackTransactionAsync();
public async Task CommitTransactionAsync()
=> await _context.Database.CommitTransactionAsync();

public async Task AddAsync(T model)
=> await _model.AddAsync(model);
public async Task AddRangeAsync(IEnumerable<T> models)
Expand Down
Loading

0 comments on commit ddbf592

Please sign in to comment.