同步OpenAuth.Core,增加多数据源

This commit is contained in:
ÂëÉñ 2020-12-29 23:52:06 +08:00 committed by yubaolee
parent 20a717b2e6
commit 304a0eb54d
40 changed files with 119 additions and 83 deletions

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
@ -12,7 +13,7 @@ namespace OpenAuth.App
/// <summary>
/// 分类管理
/// </summary>
public class AppManager : BaseApp<Application>
public class AppManager : BaseApp<Application,OpenAuthDBContext>
{
public void Add(Application Application)
{
@ -36,7 +37,7 @@ namespace OpenAuth.App
return applications.ToList();
}
public AppManager(IUnitWork unitWork, IRepository<Application> repository,IAuth auth) : base(unitWork, repository, auth)
public AppManager(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Application,OpenAuthDBContext> repository,IAuth auth) : base(unitWork, repository, auth)
{
}
}

View File

@ -14,6 +14,7 @@
//</summary>
// ***********************************************************************
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
@ -27,11 +28,11 @@ namespace OpenAuth.App
{
private SystemAuthStrategy _systemAuth;
private NormalAuthStrategy _normalAuthStrategy;
private readonly IUnitWork _unitWork;
private readonly IUnitWork<OpenAuthDBContext> _unitWork;
public AuthContextFactory(SystemAuthStrategy sysStrategy
, NormalAuthStrategy normalAuthStrategy
, IUnitWork unitWork)
, IUnitWork<OpenAuthDBContext> unitWork)
{
_systemAuth = sysStrategy;
_normalAuthStrategy = normalAuthStrategy;

View File

@ -19,6 +19,7 @@ using System.Collections.Generic;
using System.Linq;
using Infrastructure;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
@ -27,7 +28,7 @@ namespace OpenAuth.App
/// <summary>
/// 普通用户授权策略
/// </summary>
public class NormalAuthStrategy :BaseApp<User>, IAuthStrategy
public class NormalAuthStrategy :BaseApp<User,OpenAuthDBContext>, IAuthStrategy
{
protected User _user;
@ -134,7 +135,7 @@ namespace OpenAuth.App
//用户角色
public NormalAuthStrategy(IUnitWork unitWork, IRepository<User> repository, DbExtension dbExtension) : base(unitWork, repository,null)
public NormalAuthStrategy(IUnitWork<OpenAuthDBContext> unitWork, IRepository<User,OpenAuthDBContext> repository, DbExtension dbExtension) : base(unitWork, repository,null)
{
_dbExtension = dbExtension;
}

View File

@ -19,6 +19,7 @@ using System.Collections.Generic;
using System.Linq;
using Infrastructure;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
@ -29,7 +30,7 @@ namespace OpenAuth.App
/// <para>超级管理员权限</para>
/// <para>超级管理员使用guid.empty为ID可以根据需要修改</para>
/// </summary>
public class SystemAuthStrategy : BaseApp<User>, IAuthStrategy
public class SystemAuthStrategy : BaseApp<User,OpenAuthDBContext>, IAuthStrategy
{
protected User _user;
private DbExtension _dbExtension;
@ -97,7 +98,7 @@ namespace OpenAuth.App
}
public SystemAuthStrategy(IUnitWork unitWork, IRepository<User> repository, DbExtension dbExtension) : base(unitWork, repository, null)
public SystemAuthStrategy(IUnitWork<OpenAuthDBContext> unitWork, IRepository<User,OpenAuthDBContext> repository, DbExtension dbExtension) : base(unitWork, repository, null)
{
_dbExtension = dbExtension;
_user = new User

View File

@ -41,8 +41,8 @@ namespace OpenAuth.App
var builder = new ContainerBuilder();
//注册数据库基础操作和工作单元
services.AddScoped(typeof(IRepository<>), typeof(BaseRepository<>));
services.AddScoped(typeof(IUnitWork), typeof(UnitWork));
services.AddScoped(typeof(IRepository<,>), typeof(BaseRepository<,>));
services.AddScoped(typeof(IUnitWork<>), typeof(UnitWork<>));
//注入授权
builder.RegisterType(typeof(LocalAuth)).As(typeof(IAuth));
@ -77,8 +77,8 @@ namespace OpenAuth.App
{
//注册数据库基础操作和工作单元
builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IRepository<>));
builder.RegisterType(typeof(UnitWork)).As(typeof(IUnitWork));
builder.RegisterGeneric(typeof(BaseRepository<,>)).As(typeof(IRepository<,>));
builder.RegisterGeneric(typeof(UnitWork<>)).As(typeof(IUnitWork<>));
//注入授权
builder.RegisterType(typeof(LocalAuth)).As(typeof(IAuth));

View File

@ -1,6 +1,7 @@
using System;
using System.Linq;
using Infrastructure;
using Microsoft.EntityFrameworkCore;
using OpenAuth.App.Interface;
using OpenAuth.Repository.Core;
using OpenAuth.Repository.Domain;
@ -13,22 +14,22 @@ namespace OpenAuth.App
/// <para>如用户管理Class UserManagerApp:BaseApp<User></para>
/// </summary>
/// <typeparam name="T"></typeparam>
public class BaseApp<T> where T : Entity
public class BaseApp<T, TDbContext> where T : Entity where TDbContext: DbContext
{
/// <summary>
/// 用于普通的数据库操作
/// </summary>
protected IRepository<T> Repository;
protected IRepository<T, TDbContext> Repository;
/// <summary>
/// 用于事务操作
/// <para>使用详见http://doc.openauth.me/core/unitwork.html</para>
/// </summary>
protected IUnitWork UnitWork;
protected IUnitWork<TDbContext> UnitWork;
protected IAuth _auth;
public BaseApp(IUnitWork unitWork, IRepository<T> repository, IAuth auth)
public BaseApp(IUnitWork<TDbContext> unitWork, IRepository<T,TDbContext> repository, IAuth auth)
{
UnitWork = unitWork;
Repository = repository;

View File

@ -1,4 +1,5 @@
using System.Linq;
using Microsoft.EntityFrameworkCore;
using OpenAuth.App.Interface;
using OpenAuth.Repository.Core;
using OpenAuth.Repository.Interface;
@ -9,11 +10,11 @@ namespace OpenAuth.App
/// 树状结构处理
/// </summary>
/// <typeparam name="T"></typeparam>
public class BaseTreeApp<T> :BaseApp<T> where T : TreeEntity
public class BaseTreeApp<T,TDbContext> :BaseApp<T,TDbContext> where T : TreeEntity where TDbContext :DbContext
{
public BaseTreeApp(IUnitWork unitWork, IRepository<T> repository, IAuth auth)
public BaseTreeApp(IUnitWork<TDbContext> unitWork, IRepository<T, TDbContext> repository, IAuth auth)
: base(unitWork, repository,auth)
{
}

View File

@ -16,6 +16,7 @@ using Microsoft.Extensions.Options;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Core;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
@ -23,7 +24,7 @@ using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class BuilderTableApp : BaseApp<BuilderTable>
public class BuilderTableApp : BaseApp<BuilderTable,OpenAuthDBContext>
{
private BuilderTableColumnApp _builderTableColumnApp;
private CategoryApp _categoryApp;
@ -33,7 +34,7 @@ namespace OpenAuth.App
private string _startName = "";
private IOptions<AppSetting> _appConfiguration;
public BuilderTableApp(IUnitWork unitWork, IRepository<BuilderTable> repository,
public BuilderTableApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<BuilderTable,OpenAuthDBContext> repository,
RevelanceManagerApp app, IAuth auth, DbExtension dbExtension, BuilderTableColumnApp builderTableColumnApp,
IOptions<AppSetting> appConfiguration, CategoryApp categoryApp) : base(unitWork, repository, auth)
{

View File

@ -6,15 +6,16 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class BuilderTableColumnApp : BaseApp<BuilderTableColumn>
public class BuilderTableColumnApp : BaseApp<BuilderTableColumn,OpenAuthDBContext>
{
public BuilderTableColumnApp(IUnitWork unitWork, IRepository<BuilderTableColumn> repository,
public BuilderTableColumnApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<BuilderTableColumn,OpenAuthDBContext> repository,
IAuth auth) : base(unitWork, repository,auth)
{
}

View File

@ -6,13 +6,14 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class CategoryApp : BaseApp<Category>
public class CategoryApp : BaseApp<Category,OpenAuthDBContext>
{
/// <summary>
/// 加载列表
@ -90,7 +91,7 @@ namespace OpenAuth.App
return Repository.Find(u => u.TypeId == typeId).ToList();
}
public CategoryApp(IUnitWork unitWork, IRepository<Category> repository,IAuth auth) : base(unitWork, repository, auth)
public CategoryApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Category,OpenAuthDBContext> repository,IAuth auth) : base(unitWork, repository, auth)
{
}
}

View File

@ -6,13 +6,14 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class CategoryTypeApp : BaseApp<CategoryType>
public class CategoryTypeApp : BaseApp<CategoryType,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
@ -71,7 +72,7 @@ namespace OpenAuth.App
return UnitWork.Find<CategoryType>(null).ToList();
}
public CategoryTypeApp(IUnitWork unitWork, IRepository<CategoryType> repository,
public CategoryTypeApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<CategoryType,OpenAuthDBContext> repository,
RevelanceManagerApp app, IAuth auth) : base(unitWork, repository,auth)
{
_revelanceApp = app;

View File

@ -5,13 +5,14 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class DataPrivilegeRuleApp : BaseApp<DataPrivilegeRule>
public class DataPrivilegeRuleApp : BaseApp<DataPrivilegeRule,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
/// <summary>
@ -78,7 +79,7 @@ namespace OpenAuth.App
}
public DataPrivilegeRuleApp(IUnitWork unitWork, IRepository<DataPrivilegeRule> repository,
public DataPrivilegeRuleApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<DataPrivilegeRule,OpenAuthDBContext> repository,
RevelanceManagerApp app, IAuth auth) : base(unitWork, repository, auth)
{
_revelanceApp = app;

View File

@ -12,6 +12,7 @@ using Microsoft.Extensions.Options;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
@ -20,14 +21,14 @@ namespace OpenAuth.App
/// <summary>
/// 文件管理
/// </summary>
public class FileApp : BaseApp<UploadFile>
public class FileApp : BaseApp<UploadFile,OpenAuthDBContext>
{
private ILogger<FileApp> _logger;
private string _filePath;
private string _dbFilePath; //数据库中的文件路径
private string _dbThumbnail; //数据库中的缩略图路径
public FileApp(IOptions<AppSetting> setOptions, IUnitWork unitWork, IRepository<UploadFile> repository,
public FileApp(IOptions<AppSetting> setOptions, IUnitWork<OpenAuthDBContext> unitWork, IRepository<UploadFile,OpenAuthDBContext> repository,
ILogger<FileApp> logger, IAuth auth)
: base(unitWork, repository, auth)
{

View File

@ -26,13 +26,14 @@ using System.Linq.Expressions;
using System.Net.Http;
using System.Threading.Tasks;
using Infrastructure.Helpers;
using OpenAuth.Repository;
namespace OpenAuth.App
{
/// <summary>
/// 工作流实例表操作
/// </summary>
public class FlowInstanceApp : BaseApp<FlowInstance>
public class FlowInstanceApp : BaseApp<FlowInstance,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
private FlowSchemeApp _flowSchemeApp;
@ -551,7 +552,7 @@ namespace OpenAuth.App
});
}
public FlowInstanceApp(IUnitWork unitWork, IRepository<FlowInstance> repository
public FlowInstanceApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<FlowInstance,OpenAuthDBContext> repository
, RevelanceManagerApp app, FlowSchemeApp flowSchemeApp, FormApp formApp, IHttpClientFactory httpClientFactory,IAuth auth, IServiceProvider serviceProvider)
: base(unitWork, repository, auth)
{

View File

@ -4,12 +4,13 @@ using System.Threading.Tasks;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class FlowSchemeApp :BaseApp<FlowScheme>
public class FlowSchemeApp :BaseApp<FlowScheme,OpenAuthDBContext>
{
public void Add(FlowScheme flowScheme)
{
@ -65,7 +66,7 @@ namespace OpenAuth.App
return result;
}
public FlowSchemeApp(IUnitWork unitWork, IRepository<FlowScheme> repository,IAuth auth) : base(unitWork, repository, auth)
public FlowSchemeApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<FlowScheme,OpenAuthDBContext> repository,IAuth auth) : base(unitWork, repository, auth)
{
}
}

View File

@ -6,13 +6,14 @@ using Microsoft.Extensions.Options;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class FormApp : BaseApp<Form>
public class FormApp : BaseApp<Form,OpenAuthDBContext>
{
private IAuth _auth;
private IOptions<AppSetting> _appConfiguration;
@ -76,7 +77,7 @@ namespace OpenAuth.App
return form.MapTo<FormResp>();
}
public FormApp(IUnitWork unitWork, IRepository<Form> repository,
public FormApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Form,OpenAuthDBContext> repository,
IAuth auth, IOptions<AppSetting> appConfiguration) : base(unitWork, repository, auth)
{
_auth = auth;

View File

@ -3,13 +3,14 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class FrmLeaveReqApp : BaseApp<FrmLeaveReq>, ICustomerForm
public class FrmLeaveReqApp : BaseApp<FrmLeaveReq,OpenAuthDBContext>, ICustomerForm
{
private RevelanceManagerApp _revelanceApp;
@ -39,7 +40,7 @@ namespace OpenAuth.App
}
public FrmLeaveReqApp(IUnitWork unitWork, IRepository<FrmLeaveReq> repository,
public FrmLeaveReqApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<FrmLeaveReq,OpenAuthDBContext> repository,
RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
{
_revelanceApp = app;

View File

@ -3,12 +3,13 @@ using System.Linq;
using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class ModuleManagerApp : BaseTreeApp<Module>
public class ModuleManagerApp : BaseTreeApp<Module,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
@ -172,7 +173,7 @@ namespace OpenAuth.App
#endregion
public ModuleManagerApp(IUnitWork unitWork, IRepository<Module> repository
public ModuleManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Module,OpenAuthDBContext> repository
, RevelanceManagerApp app, IAuth auth) : base(unitWork, repository, auth)
{
_revelanceApp = app;

View File

@ -8,6 +8,7 @@ using OpenAuth.App.Interface;
using OpenAuth.App.Jobs;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
using Quartz;
@ -15,7 +16,7 @@ using Quartz;
namespace OpenAuth.App
{
public class OpenJobApp : BaseApp<OpenJob>
public class OpenJobApp : BaseApp<OpenJob, OpenAuthDBContext>
{
private SysLogApp _sysLogApp;
private IScheduler _scheduler;
@ -171,7 +172,7 @@ namespace OpenAuth.App
#endregion
public OpenJobApp(IUnitWork unitWork, IRepository<OpenJob> repository,
public OpenJobApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<OpenJob,OpenAuthDBContext> repository,
IAuth auth, SysLogApp sysLogApp, IScheduler scheduler, ILogger<OpenJobApp> logger) : base(unitWork, repository, auth)
{
_sysLogApp = sysLogApp;

View File

@ -3,12 +3,13 @@ using System.Linq;
using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class OrgManagerApp : BaseTreeApp<Org>
public class OrgManagerApp : BaseTreeApp<Org,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
/// <summary>
@ -81,7 +82,7 @@ namespace OpenAuth.App
return result.ToList();
}
public OrgManagerApp(IUnitWork unitWork, IRepository<Org> repository,IAuth auth,
public OrgManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Org,OpenAuthDBContext> repository,IAuth auth,
RevelanceManagerApp revelanceApp) : base(unitWork, repository, auth)
{
_revelanceApp = revelanceApp;

View File

@ -6,6 +6,7 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
@ -14,7 +15,7 @@ namespace OpenAuth.App
/// <summary>
/// 分类管理
/// </summary>
public class ResourceApp:BaseApp<Resource>
public class ResourceApp:BaseApp<Resource,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
@ -85,7 +86,7 @@ namespace OpenAuth.App
return result;
}
public ResourceApp(IUnitWork unitWork, IRepository<Resource> repository
public ResourceApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Resource,OpenAuthDBContext> repository
,RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
{
_revelanceApp = app;

View File

@ -4,15 +4,16 @@ using System.Linq;
using Microsoft.Extensions.Logging;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class RevelanceManagerApp : BaseApp<Relevance>
public class RevelanceManagerApp : BaseApp<Relevance,OpenAuthDBContext>
{
private readonly ILogger<RevelanceManagerApp> _logger;
public RevelanceManagerApp(IUnitWork unitWork, IRepository<Relevance> repository, IAuth auth, ILogger<RevelanceManagerApp> logger) : base(unitWork,
public RevelanceManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Relevance,OpenAuthDBContext> repository, IAuth auth, ILogger<RevelanceManagerApp> logger) : base(unitWork,
repository, auth)
{
_logger = logger;

View File

@ -6,10 +6,11 @@ using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
using System.Linq;
using OpenAuth.App.Request;
using OpenAuth.Repository;
namespace OpenAuth.App
{
public class RoleApp : BaseApp<Role>
public class RoleApp : BaseApp<Role,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
@ -73,7 +74,7 @@ namespace OpenAuth.App
}
public RoleApp(IUnitWork unitWork, IRepository<Role> repository,
public RoleApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Role,OpenAuthDBContext> repository,
RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
{
_revelanceApp = app;

View File

@ -4,6 +4,7 @@
*/
using System;
using Infrastructure.Cache;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
@ -14,11 +15,11 @@ namespace OpenAuth.App.SSO
{
//这个地方使用IRepository<User> 而不使用UserManagerApp是防止循环依赖
public IRepository<User> _app;
public IRepository<User,OpenAuthDBContext> _app;
private ICacheContext _cacheContext;
private AppInfoService _appInfoService;
public LoginParse( AppInfoService infoService, ICacheContext cacheContext, IRepository<User> userApp)
public LoginParse( AppInfoService infoService, ICacheContext cacheContext, IRepository<User,OpenAuthDBContext> userApp)
{
_appInfoService = infoService;
_cacheContext = cacheContext;

View File

@ -3,13 +3,14 @@ using System.Reflection;
using System.Threading.Tasks;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class SysLogApp : BaseApp<SysLog>
public class SysLogApp : BaseApp<SysLog,OpenAuthDBContext>
{
/// <summary>
@ -47,7 +48,7 @@ namespace OpenAuth.App
}
public SysLogApp(IUnitWork unitWork, IRepository<SysLog> repository) : base(unitWork, repository, null)
public SysLogApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<SysLog,OpenAuthDBContext> repository) : base(unitWork, repository, null)
{
}
}

View File

@ -4,13 +4,14 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class SysMessageApp : BaseApp<SysMessage>
public class SysMessageApp : BaseApp<SysMessage,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
@ -54,7 +55,7 @@ namespace OpenAuth.App
}
public SysMessageApp(IUnitWork unitWork, IRepository<SysMessage> repository,
public SysMessageApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<SysMessage,OpenAuthDBContext> repository,
RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
{
_revelanceApp = app;

View File

@ -8,6 +8,7 @@ using Moq;
using NUnit.Framework;
using OpenAuth.App.Request;
using OpenAuth.App.SSO;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
@ -48,7 +49,7 @@ namespace OpenAuth.App.Test
private async Task AddOrUpdate()
{
var repository = _autofacServiceProvider.GetService<IRepository<User>>();
var repository = _autofacServiceProvider.GetService<IRepository<User,OpenAuthDBContext>>();
var account = "user_" + DateTime.Now.ToString("yyyy_MM_dd HH:mm:ss");

View File

@ -7,18 +7,19 @@ using Infrastructure.Extensions;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class UserManagerApp : BaseApp<User>
public class UserManagerApp : BaseApp<User,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
private OrgManagerApp _orgManagerApp;
public UserManagerApp(IUnitWork unitWork, IRepository<User> repository,
public UserManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<User,OpenAuthDBContext> repository,
RevelanceManagerApp app,IAuth auth, OrgManagerApp orgManagerApp) : base(unitWork, repository, auth)
{
_revelanceApp = app;

View File

@ -5,13 +5,14 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class WmsInboundOrderDtblApp : BaseApp<WmsInboundOrderDtbl>
public class WmsInboundOrderDtblApp : BaseApp<WmsInboundOrderDtbl,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
private DbExtension _dbExtension;
@ -99,7 +100,7 @@ namespace OpenAuth.App
}
public WmsInboundOrderDtblApp(IUnitWork unitWork, IRepository<WmsInboundOrderDtbl> repository,
public WmsInboundOrderDtblApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<WmsInboundOrderDtbl,OpenAuthDBContext> repository,
RevelanceManagerApp app, IAuth auth, DbExtension dbExtension) : base(unitWork, repository,auth)
{
_dbExtension = dbExtension;

View File

@ -5,13 +5,14 @@ using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class WmsInboundOrderTblApp : BaseApp<WmsInboundOrderTbl>
public class WmsInboundOrderTblApp : BaseApp<WmsInboundOrderTbl,OpenAuthDBContext>
{
private RevelanceManagerApp _revelanceApp;
private WmsInboundOrderDtblApp _wmsInboundOrderDtblApp;
@ -130,7 +131,7 @@ namespace OpenAuth.App
});
}
public WmsInboundOrderTblApp(IUnitWork unitWork, IRepository<WmsInboundOrderTbl> repository,
public WmsInboundOrderTblApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<WmsInboundOrderTbl,OpenAuthDBContext> repository,
RevelanceManagerApp app, IAuth auth, WmsInboundOrderDtblApp wmsInboundOrderDtblApp) : base(unitWork,
repository, auth)
{

View File

@ -11,11 +11,11 @@ using Z.EntityFramework.Plus;
namespace OpenAuth.Repository
{
public class BaseRepository<T> : IRepository<T> where T : BaseEntity
public class BaseRepository<T,TDbContext> : IRepository<T,TDbContext> where T : BaseEntity where TDbContext: DbContext
{
private OpenAuthDBContext _context;
private TDbContext _context;
public BaseRepository(OpenAuthDBContext context)
public BaseRepository(TDbContext context)
{
_context = context;
}

View File

@ -16,10 +16,11 @@ using System;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace OpenAuth.Repository.Interface
{
public interface IRepository<T> where T : class
public interface IRepository<T,TDbContext> where T : class where TDbContext: DbContext
{
/// <summary>
/// 返回一个单独的实体如果记录多于1个则取第一个

View File

@ -6,13 +6,14 @@
// Last Modified By : yubaolee
// Last Modified On : 12-15-2020
// Contact : Microsoft
// File: IUnitWork.cs
// File: IUnitWork<OpenAuthDBContext>.cs
// ***********************************************************************
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using OpenAuth.Repository.Core;
namespace OpenAuth.Repository.Interface
@ -25,7 +26,7 @@ namespace OpenAuth.Repository.Interface
/// <para>2 需要多表联合查询</para>
/// <para>因为架构采用的是EF访问数据库暂时可以不用考虑采用传统Unit Work的注册机制</para>
/// </summary>
public interface IUnitWork
public interface IUnitWork<TDbContext> where TDbContext:DbContext
{
/// <summary>
/// EF默认情况下每调用一次SaveChanges()都会执行一个单独的事务
@ -36,7 +37,7 @@ namespace OpenAuth.Repository.Interface
/// 返回DbContext,用于多线程等极端情况
/// </summary>
/// <returns></returns>
OpenAuthDBContext GetDbContext();
DbContext GetDbContext();
/// <summary>
/// 返回一个单独的实体如果记录多于1个则取第一个
/// </summary>

View File

@ -22,8 +22,8 @@ namespace OpenAuth.Repository.Test
var serviceCollection = GetService();
serviceCollection.AddMemoryCache();
serviceCollection.AddOptions();
serviceCollection.AddScoped(typeof(IRepository<>), typeof(BaseRepository<>));
serviceCollection.AddScoped(typeof(IUnitWork), typeof(UnitWork));
serviceCollection.AddScoped(typeof(IRepository<,>), typeof(BaseRepository<,>));
serviceCollection.AddScoped(typeof(IUnitWork<>), typeof(UnitWork<>));
serviceCollection.AddDbContext<OpenAuthDBContext>(options =>
options.UseSqlServer("Data Source=.;Initial Catalog=OpenAuthDB;User=sa;Password=000000;Integrated Security=True"));

View File

@ -83,7 +83,7 @@ namespace OpenAuth.Repository.Test
Console.WriteLine(account);
var repository = _autofacServiceProvider.GetService<IRepository<User>>();
var repository = _autofacServiceProvider.GetService<IRepository<User,OpenAuthDBContext>>();
//新增
repository.Add(new User

View File

@ -17,7 +17,7 @@ namespace OpenAuth.Repository.Test
[Test]
public void NormalSubmit()
{
var unitWork = _autofacServiceProvider.GetService<IUnitWork>();
var unitWork = _autofacServiceProvider.GetService<IUnitWork<OpenAuthDBContext>>();
unitWork.ExecuteWithTransaction(() =>
{
var account = "user_" + DateTime.Now.ToString("yyyy_MM_dd HH:mm:ss");
@ -33,7 +33,7 @@ namespace OpenAuth.Repository.Test
[Test]
public void SubmitWithRollback()
{
var unitWork = _autofacServiceProvider.GetService<IUnitWork>();
var unitWork = _autofacServiceProvider.GetService<IUnitWork<OpenAuthDBContext>>();
var account = "user_" + DateTime.Now.ToString("yyyy_MM_dd HH:mm:ss");
try
{
@ -57,7 +57,7 @@ namespace OpenAuth.Repository.Test
/// <summary>
/// 测试添加单个修改Z.EntityFramework.Plus条件修改
/// </summary>
private void AddAndUpdate(string account, IUnitWork unitWork)
private void AddAndUpdate(string account, IUnitWork<OpenAuthDBContext> unitWork)
{
var user = new User
{

View File

@ -12,11 +12,11 @@ using Z.EntityFramework.Plus;
namespace OpenAuth.Repository
{
public class UnitWork: IUnitWork
public class UnitWork<TDbContext>: IUnitWork<TDbContext> where TDbContext: DbContext
{
private OpenAuthDBContext _context;
private TDbContext _context;
public UnitWork(OpenAuthDBContext context)
public UnitWork(TDbContext context)
{
_context = context;
}
@ -45,7 +45,7 @@ namespace OpenAuth.Repository
/// <summary>
/// 返回DbContext,用于多线程等极端情况
/// </summary>
public OpenAuthDBContext GetDbContext()
public DbContext GetDbContext()
{
return _context;
}

View File

@ -1,16 +1,18 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
namespace OpenAuth.App
{
public class {ModuleCode} : BaseApp<{ClassName}>
public class {ModuleCode} : BaseApp<{ClassName},OpenAuthDBContext>
{
/// <summary>
@ -64,7 +66,7 @@ namespace OpenAuth.App
}
public {ModuleCode}(IUnitWork unitWork, IRepository<{ClassName}> repository, IAuth auth) : base(unitWork, repository, auth)
public {ModuleCode}(IUnitWork<OpenAuthDBContext> unitWork, IRepository<{ClassName},OpenAuthDBContext> repository, IAuth auth) : base(unitWork, repository, auth)
{
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App;

View File

@ -1,7 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information"
"Default": "Information",
"System": "Error",
"Microsoft": "Error"
}
},
"AllowedHosts": "*",