aboutsummaryrefslogtreecommitdiff
path: root/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-12-19 12:24:54 +0800
committercrupest <crupest@outlook.com>2022-12-20 20:32:53 +0800
commite9b958cc41a3b941d878fd455e297a50e050be1a (patch)
tree1e431c0b2038cde586be12cfb96c6c2da75b11e8 /docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs
parentf73342cb6b0592d3a6310f9a12fd40b4bf218e5c (diff)
downloadcrupest-e9b958cc41a3b941d878fd455e297a50e050be1a.tar.gz
crupest-e9b958cc41a3b941d878fd455e297a50e050be1a.tar.bz2
crupest-e9b958cc41a3b941d878fd455e297a50e050be1a.zip
Develop secret api. v43
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs')
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs11
1 files changed, 8 insertions, 3 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs
index 184ac0a..27f0c85 100644
--- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudService.cs
@@ -12,9 +12,9 @@ public class CrudService<TEntity> : IDisposable where TEntity : class
protected readonly EntityJsonHelper<TEntity> _jsonHelper;
private readonly ILogger<CrudService<TEntity>> _logger;
- public CrudService(string? connectionName, ITableInfoFactory tableInfoFactory, IDbConnectionFactory dbConnectionFactory, EntityJsonHelper<TEntity> jsonHelper, ILoggerFactory loggerFactory)
+ public CrudService(ITableInfoFactory tableInfoFactory, IDbConnectionFactory dbConnectionFactory, EntityJsonHelper<TEntity> jsonHelper, ILoggerFactory loggerFactory)
{
- _connectionName = connectionName;
+ _connectionName = GetConnectionName();
_table = tableInfoFactory.Get(typeof(TEntity));
_dbConnection = dbConnectionFactory.Get(_connectionName);
_jsonHelper = jsonHelper;
@@ -23,6 +23,11 @@ public class CrudService<TEntity> : IDisposable where TEntity : class
CheckDatabase(_dbConnection);
}
+ protected virtual string GetConnectionName()
+ {
+ return typeof(TEntity).Name;
+ }
+
public EntityJsonHelper<TEntity> JsonHelper => _jsonHelper;
protected virtual void CheckDatabase(IDbConnection dbConnection)
@@ -33,7 +38,7 @@ public class CrudService<TEntity> : IDisposable where TEntity : class
}
}
- private void DoInitializeDatabase(IDbConnection connection)
+ protected virtual void DoInitializeDatabase(IDbConnection connection)
{
using var transaction = connection.BeginTransaction();
connection.Execute(_table.GenerateCreateTableSql(), transaction: transaction);