From 6e5e47f1943d257d2d8d8ca8926f2f10b8107de4 Mon Sep 17 00:00:00 2001 From: Nikoo Asadnejad Date: Wed, 20 Mar 2024 18:09:35 +0330 Subject: [PATCH] refactor(genericRepository) : add T constraints --- .../{ => Interfaces}/Command/IRepository.Async.cs | 2 +- .../{ => Interfaces}/Command/IRepository.Sync.cs | 4 +++- .../Shared/GenericRepository/{ => Interfaces}/IUnitOfWork.cs | 0 .../{ => Interfaces}/Query/IQueryGenericRepository.Async.cs | 3 ++- .../{ => Interfaces}/Query/IQueryGenericRepository.Sync.cs | 3 ++- .../Repository/GenericRepository/Command/Repository.Async.cs | 2 +- .../Repository/GenericRepository/Command/Repository.Sync.cs | 2 +- .../GenericRepository/Query/QueryGenericRepository.Async.cs | 3 ++- 8 files changed, 12 insertions(+), 7 deletions(-) rename Src/Product.Domain/Shared/GenericRepository/{ => Interfaces}/Command/IRepository.Async.cs (90%) rename Src/Product.Domain/Shared/GenericRepository/{ => Interfaces}/Command/IRepository.Sync.cs (80%) rename Src/Product.Domain/Shared/GenericRepository/{ => Interfaces}/IUnitOfWork.cs (100%) rename Src/Product.Domain/Shared/GenericRepository/{ => Interfaces}/Query/IQueryGenericRepository.Async.cs (95%) rename Src/Product.Domain/Shared/GenericRepository/{ => Interfaces}/Query/IQueryGenericRepository.Sync.cs (94%) diff --git a/Src/Product.Domain/Shared/GenericRepository/Command/IRepository.Async.cs b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Async.cs similarity index 90% rename from Src/Product.Domain/Shared/GenericRepository/Command/IRepository.Async.cs rename to Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Async.cs index c30055b..2880080 100644 --- a/Src/Product.Domain/Shared/GenericRepository/Command/IRepository.Async.cs +++ b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Async.cs @@ -3,7 +3,7 @@ namespace Product.Domain.Shared.GenericRepository.GenericRepository.Command; -public partial interface IRepository where T : BaseEntity +public partial interface IRepository where T : IAggregateRoot { Task AddAsync(T model); diff --git a/Src/Product.Domain/Shared/GenericRepository/Command/IRepository.Sync.cs b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Sync.cs similarity index 80% rename from Src/Product.Domain/Shared/GenericRepository/Command/IRepository.Sync.cs rename to Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Sync.cs index 50d134a..178ed4f 100644 --- a/Src/Product.Domain/Shared/GenericRepository/Command/IRepository.Sync.cs +++ b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Sync.cs @@ -1,6 +1,8 @@ +using Product.Domain.Shared.Base; + namespace Product.Domain.Shared.GenericRepository.GenericRepository.Command; -public partial interface IRepository +public partial interface IRepository where T : IAggregateRoot { void RollbackTransaction(); void CommitTransaction(); diff --git a/Src/Product.Domain/Shared/GenericRepository/IUnitOfWork.cs b/Src/Product.Domain/Shared/GenericRepository/Interfaces/IUnitOfWork.cs similarity index 100% rename from Src/Product.Domain/Shared/GenericRepository/IUnitOfWork.cs rename to Src/Product.Domain/Shared/GenericRepository/Interfaces/IUnitOfWork.cs diff --git a/Src/Product.Domain/Shared/GenericRepository/Query/IQueryGenericRepository.Async.cs b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Async.cs similarity index 95% rename from Src/Product.Domain/Shared/GenericRepository/Query/IQueryGenericRepository.Async.cs rename to Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Async.cs index f540a5b..0501875 100644 --- a/Src/Product.Domain/Shared/GenericRepository/Query/IQueryGenericRepository.Async.cs +++ b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Async.cs @@ -1,9 +1,10 @@ using System.Linq.Expressions; +using Product.Domain.Shared.Base; using Product.Domain.Shared.GenericRepository.Enums; namespace Product.Domain.Shared.GenericRepository.GenericRepository.Query; -public partial interface IQueryGenericRepository +public partial interface IQueryGenericRepository where T : BaseEntity { Task FindAsync(long id); Task> GetQueryableAsync(); diff --git a/Src/Product.Domain/Shared/GenericRepository/Query/IQueryGenericRepository.Sync.cs b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Sync.cs similarity index 94% rename from Src/Product.Domain/Shared/GenericRepository/Query/IQueryGenericRepository.Sync.cs rename to Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Sync.cs index e663ed1..04e1f63 100644 --- a/Src/Product.Domain/Shared/GenericRepository/Query/IQueryGenericRepository.Sync.cs +++ b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Sync.cs @@ -1,9 +1,10 @@ using System.Linq.Expressions; +using Product.Domain.Shared.Base; using Product.Domain.Shared.GenericRepository.Enums; namespace Product.Domain.Shared.GenericRepository.GenericRepository.Query; -public partial interface IQueryGenericRepository +public partial interface IQueryGenericRepository where T : BaseEntity { IQueryable GetQueryable(); T Find(long id); diff --git a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Command/Repository.Async.cs b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Command/Repository.Async.cs index 0d3c03e..1784744 100644 --- a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Command/Repository.Async.cs +++ b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Command/Repository.Async.cs @@ -6,7 +6,7 @@ namespace Product.Infrastructure.Data.Repository.GenericRepository.Command; -public sealed partial class Repository : IRepository where T : BaseEntity +public sealed partial class Repository : IRepository where T : BaseEntity , IAggregateRoot { private readonly CommandContext _context; diff --git a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Command/Repository.Sync.cs b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Command/Repository.Sync.cs index 0dc4e5e..a63e937 100644 --- a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Command/Repository.Sync.cs +++ b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Command/Repository.Sync.cs @@ -4,7 +4,7 @@ namespace Product.Infrastructure.Data.Repository.GenericRepository.Command; -public sealed partial class Repository where T : BaseEntity +public sealed partial class Repository where T : BaseEntity , IAggregateRoot { public IDbContextTransaction BeginTransaction() { diff --git a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/QueryGenericRepository.Async.cs b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/QueryGenericRepository.Async.cs index 303d499..08aa513 100644 --- a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/QueryGenericRepository.Async.cs +++ b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/QueryGenericRepository.Async.cs @@ -1,12 +1,13 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore; +using Product.Domain.Shared.Base; using Product.Domain.Shared.GenericRepository.Enums; using Product.Domain.Shared.GenericRepository.GenericRepository.Query; using Product.Infrastructure.Data.Context; namespace Product.Infrastructure.Data.Repository.GenericRepository.Query; -public sealed partial class QueryGenericRepository : IQueryGenericRepository +public sealed partial class QueryGenericRepository : IQueryGenericRepository where T : BaseEntity { private readonly QueryContext _context; private readonly DbSet _model;