Skip to content

Commit

Permalink
Merge pull request #13 from Nikoo-Asadnejad/develop
Browse files Browse the repository at this point in the history
feat: add support of multiple dbcontext to unit of work
  • Loading branch information
Nikoo-Asadnejad authored Sep 27, 2024
2 parents 3550d9d + 3cc96f3 commit 9eabaa6
Show file tree
Hide file tree
Showing 112 changed files with 2,420 additions and 185 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1,188 changes: 1,068 additions & 120 deletions GenericRepository.Tests/bin/Debug/net8.0/GenericRepository.Tests.deps.json

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified GenericRepository.Tests/bin/Debug/net8.0/GenericRepository.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Expand Up @@ -13,7 +13,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("GenericRepository.Tests")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ed492562eb679f2f0c779228516e345e29cb3f29")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f0ddcf1dcaf2006e1e2ea5ee5ce4ce8bcc4f3561")]
[assembly: System.Reflection.AssemblyProductAttribute("GenericRepository.Tests")]
[assembly: System.Reflection.AssemblyTitleAttribute("GenericRepository.Tests")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
393db6154241468ab21270c1ecf289861edb70a371b63523943b35762ba3dac9
e03e0ff31eebecae1a468731ba49cc50002228c90d766e56b23fdd38e08eb357
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fbad29cc9496a5b52fd17d71ee7daf8d9c0362c10b0b995dded4e897a8073448
734b295e73d8265cd842d926529953d6531840fb66ae83939a79be0317eb3361
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/zh-Hant/Microsoft.TestPlatform.CommunicationUtilities.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/zh-Hant/Microsoft.TestPlatform.CrossPlatEngine.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/zh-Hant/Microsoft.VisualStudio.TestPlatform.Common.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/win/lib/net6.0/System.Diagnostics.EventLog.Messages.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/win/lib/net6.0/System.Diagnostics.EventLog.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/GenericRepository.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/GenericRepository.pdb
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/obj/Debug/net8.0/GenericRepository.Tests.csproj.AssemblyReference.cache
Expand All @@ -120,3 +118,80 @@
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/obj/Debug/net8.0/GenericRepository.Tests.pdb
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/obj/Debug/net8.0/GenericRepository.Tests.genruntimeconfig.cache
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/obj/Debug/net8.0/ref/GenericRepository.Tests.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Azure.Core.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Azure.Identity.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/EFCore.BulkExtensions.Core.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/EFCore.BulkExtensions.MySql.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/EFCore.BulkExtensions.PostgreSql.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/EFCore.BulkExtensions.Sqlite.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/EFCore.BulkExtensions.SqlServer.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/EntityFramework.SqlServer.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/EntityFramework.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/EntityFramework.BulkExtensions.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/EntityFramework.MappingAPI.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/MedallionTopologicalSort.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.Bcl.AsyncInterfaces.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.Data.SqlClient.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.Data.Sqlite.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.EntityFrameworkCore.Relational.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.EntityFrameworkCore.Sqlite.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.EntityFrameworkCore.SqlServer.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.EntityFrameworkCore.SqlServer.Abstractions.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.EntityFrameworkCore.SqlServer.HierarchyId.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.Extensions.Configuration.Abstractions.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.Identity.Client.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.Identity.Client.Extensions.Msal.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.IdentityModel.Abstractions.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.IdentityModel.JsonWebTokens.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.IdentityModel.Logging.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.IdentityModel.Protocols.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.IdentityModel.Protocols.OpenIdConnect.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.IdentityModel.Tokens.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.SqlServer.Server.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Microsoft.SqlServer.Types.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/MySqlConnector.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/NetTopologySuite.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/NetTopologySuite.IO.SpatiaLite.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/NetTopologySuite.IO.SqlServerBytes.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Npgsql.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Npgsql.EntityFrameworkCore.PostgreSQL.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/Pomelo.EntityFrameworkCore.MySql.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/SQLitePCLRaw.core.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/System.ClientModel.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/System.Configuration.ConfigurationManager.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/System.IdentityModel.Tokens.Jwt.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/System.Memory.Data.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/System.Runtime.Caching.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/System.Security.Cryptography.ProtectedData.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/System.Text.Json.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/de/Microsoft.Data.SqlClient.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/es/Microsoft.Data.SqlClient.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/fr/Microsoft.Data.SqlClient.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/it/Microsoft.Data.SqlClient.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/ja/Microsoft.Data.SqlClient.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/ko/Microsoft.Data.SqlClient.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/pt-BR/Microsoft.Data.SqlClient.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/ru/Microsoft.Data.SqlClient.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/zh-Hans/Microsoft.Data.SqlClient.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/zh-Hant/Microsoft.Data.SqlClient.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/de/Microsoft.SqlServer.Types.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/es/Microsoft.SqlServer.Types.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/fr/Microsoft.SqlServer.Types.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/it/Microsoft.SqlServer.Types.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/ja/Microsoft.SqlServer.Types.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/ko/Microsoft.SqlServer.Types.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/pt-BR/Microsoft.SqlServer.Types.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/ru/Microsoft.SqlServer.Types.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/zh-Hans/Microsoft.SqlServer.Types.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/zh-Hant/Microsoft.SqlServer.Types.resources.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/unix/lib/net8.0/Microsoft.Data.SqlClient.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/win/lib/net8.0/Microsoft.Data.SqlClient.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/win-arm/native/Microsoft.Data.SqlClient.SNI.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/win-arm64/native/Microsoft.Data.SqlClient.SNI.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/win-x64/native/Microsoft.Data.SqlClient.SNI.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/win-x86/native/Microsoft.Data.SqlClient.SNI.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/win-x64/native/SqlServerSpatial160.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/win-x86/native/SqlServerSpatial160.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/win/lib/net8.0/System.Diagnostics.EventLog.Messages.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/win/lib/net8.0/System.Diagnostics.EventLog.dll
/Users/macbook/Projects/Generic Repository/GenericRepository.Tests/bin/Debug/net8.0/runtimes/win/lib/net8.0/System.Runtime.Caching.dll
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documents":{"/Users/macbook/Projects/Generic Repository/*":"https://raw.githubusercontent.com/Nikoo-Asadnejad/GenericRepository/dc89b2d70f09714087814b4ec5fc6c22a56a217f/*"}}
{"documents":{"/Users/macbook/Projects/Generic Repository/*":"https://raw.githubusercontent.com/Nikoo-Asadnejad/GenericRepository/c9ea29c11a611e048379e66ed6ee97ac21e79fac/*"}}
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion GenericRepository.Tests/obj/rider.project.model.nuget.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
17274201315108780
17274215514174141
24 changes: 20 additions & 4 deletions GenericRepository/Application/Interfaces/UnitOfWork/IUnitOfWork.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;

namespace GenericRepository.Application.Interfaces.UnitOfWork;

public interface IUnitOfWork
public interface IUnitOfWork<TContext> where TContext : DbContext
{
Task<int> SaveAsync();
int Save();
Task DisposeAsync();
void Dispose();
Task<IDbContextTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default);
Task RollbackTransactionAsync();
Task CommitTransactionAsync();
Task<IDbContextTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default);
IDbContextTransaction BeginTransaction();
Task RollbackTransactionAsync(CancellationToken cancellationToken = default);
void RollbackTransaction();
Task CommitTransactionAsync(CancellationToken cancellationToken = default);
void CommitTransaction();
Task<int> ExecuteSqlCommandAsync(string sql, object[] parameters, CancellationToken cancellationToken = default);
int ExecuteSqlCommand(string sql, params object[] parameters);
Task<List<T>> ExecuteSqlQueryAsync<T>(string sql, object[] parameters, CancellationToken cancellationToken = default) where T : class;
List<T> ExecuteSqlQuery<T>(string sql, params object[] parameters) where T : class;
Task ExecuteSqlWithinTransactionAsync(string sql, object[] parameters, CancellationToken cancellationToken = default);
void ExecuteSqlWithinTransaction(string sql, params object[] parameters);
Task<List<T>> ExecuteStoredProcedureAsync<T>(string storedProcedureName, object[] parameters, CancellationToken cancellationToken = default) where T : class;
List<T> ExecuteStoredProcedure<T>(string storedProcedureName, params object[] parameters) where T : class;
Task<int> ExecuteSqlCommandWithParamsAsync(string sql, SqlParameter[] parameters, CancellationToken cancellationToken = default);
int ExecuteSqlCommandWithParams(string sql, params SqlParameter[] parameters);
bool IsRawSqlSupported();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class GenericRepositoryConfigurator
public static void InjectServices(IServiceCollection services)
{
services.AddMemoryCache();
services.AddTransient<IUnitOfWork, UnitOfWork>();
services.AddTransient(typeof(IUnitOfWork<>), typeof(UnitOfWork<>));
services.AddScoped<DbContext, CommandContext>();
services.AddScoped<DbContext, QueryContext>();
services.AddSingleton<PublishDomainEventsInterceptor>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,7 @@ public async Task TruncateTableAsync()
var tableName = _context.Model.FindEntityType(typeof(T)).GetTableName();
await _context.Database.ExecuteSqlRawAsync($"TRUNCATE TABLE {tableName}");
}


}

Loading

0 comments on commit 9eabaa6

Please sign in to comment.